10 sloc, ⅛ kb, no-bullshit dependency injection micro-library
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.npmignore
LICENSE
README.md
index.js
index.min.js
package.json
test.js

README.md

µject

10 sloc, ⅛ kb, no-bullshit dependency injection micro-library

NPM

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();