NodeJS got prospects. He's componafide.
container.register('myComponent', ['dep1', 'dep2'], (dep1, dep2) => { /* return myComponent */ });
container.register('dep1', [], () => { /* return dep1 */ });
Convienience method for container.register(name, [], () => value);
.
Export a component in each file. Put all dependencies in closure, and return an API or value. Require nothing outside of a file or two. No regrets. Go state!
module.exports = (dep1, dep2) => {
function myPrivateMethod () {}
return class MySingleton {
static myPublicMethod () {}
}
}
Define the component in index.js or some application bootstrapping step:
container.register('myComponent', require('src/myComponent'), ['dep1', 'dep2']);
const component = container.resolve('myComponent');
module.exports = dep1 => {
function privateMethod () {}
return class SingletonAPI {
static publicMethod (arg1, arg2) {}
}
}
module.exports = Pomade => {
function applyTheDap () {}
return class DapperDan extends Pomade {
apply () {}
}
}
Still use dependency injection. If it feels stupid your are probably still doing it right.
container.constant('scope.process', process);
container.constant('pi', 3.14);