jaredhanson / jaredhanson/electrolyte
Manually adding an object to the container
- Dominant language
- JavaScript
- Stars
- 555
- Forks
- 60
- PR merge metrics
- No merged PRs in 30d
Description
I'm using hapi.js and I'd like to add the hapi server object to my electrolyte container while at the same time maintaining some of hapi's best practices.
The hapi server object maintains its own container of plugin objects, and a typical way to set up a hapi project is to use a 'bootstrap' plugin to set up the server. Mine looks like this:
```
var ioc = require('electrolyte');
var config = require('./config');
exports.register = (server, options, next) => {
server.auth.strategy('jwt', 'jwt', {
key : config('/auth/secret'),
validateFunc : require('./src/application/auth/validateJWT'),
verifyOptions : { algorithms: [ 'HS256' ] }
});
ioc.use(ioc.node('src/application'));
ioc.use(ioc.node('src/lib'));
server.route(ioc.create('example/example-routes'));
server.route(ioc.create('auth/auth-routes'));
server.route(ioc.create('user/user-routes'));
next();
};
exports.register.attributes = {
name : 'ims-bootstrap',
version : '0.0.1'
};
```
I want to make the server object that is passed into this plugin available in my electrolyte container. Is there some way to call `ioc.use` such that it will just make the already instantiated server object available in the container?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the ioc.use API and the container registration path referenced in the bootstrap example. Confirm whether an already-instantiated hapi server can be registered without construction; done means the same server object is retrievable from the container while preserving the shown plugin setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100