node-dep-injector
Dep-injector is a dependecy injector for Node.js. It supports lazy loading by registering factory methods, not just instantiated dependencies. In this case the factory method will be called only when you inject it first time.
Usage
var DI = ;var di = ; di;di; di; // 1di; // 2 , and logs: bar var fn = di; ; // 2 , without console.log
Methods
register(name, dep)
Registers a named dependency.
registerFactory(name, factoryMethod, [additionalDeps])
Registers a factory method. You can add addtional dependencies, and they will be injected when calling the factory method.
get(name)
Returns the named dependency, and instantiate it if it's a factory and the instance doesn't exist.
inject(fn, [additionalDeps])
Injects the required dependencies into the function, and returns another function. By calling the returned function you can resolve the dependencies and run the originally given function.
Running Tests
npm test
Licence
MIT © Gabor Pihaj