muject
v1.2.0
Published
10-SLOC no-bullshit dependency injection micro-library
Downloads
2
Maintainers
Readme
µject
10 sloc, ⅛ kb, no-bullshit dependency injection micro-library
Usage
Create a new injector
var modules = {},
inject = require('muject').bind(require, modules);
Require dependencies inside a module
module.exports = function myModule (depFoo, depBar, depBaz) {
this.exportA = ...;
this.exportB = ...;
};
module.exports.inject = ['foo', 'bar', 'baz'];
Register dependencies & require a module
modules.foo = inject('./my/foo'); // require, register w/ injection
modules.bar = require('./my/bar'); // require, register w/o injection
modules.baz = inject(function (bar) { // direct, register w/ injection
return bar.doSomething();
}, ['bar']);
var myModule = inject('./my/module.js');
myModule.exportA();
myModule.exportB();