node-dinjector
v1.0.46
Published
Node-DInjector, design to be a simple and practical dependency injection library.
Downloads
5
Maintainers
Readme
Node Dependency Injection
- API
- Injector
- Store
- Helper
Installation
npm i -S node-dinjector
Including library in your project
const DInjector = require('node-dinjector');
const DInjectorStore = DInjector.Store;
const DInjectorHelper = DInjector.Helper;
Example
const DInjector = require('../DInjector');
const DInjectorStore = DInjector.Store;
const DInjectorHelper = DInjector.Helper;
const injector = new DInjector();
injector.getStore().set('a', 123); // set di
class Controller {
test(a, b) {
console.log(a, b);
},
test(c, a, b) {
console.log(c, a, b);
}
}
const c = new Controller();
// replace c functions with resolved functions using injector
DInjectorHelper.mapFunctions(c, func => injector.resolve(func, c));
// call test function with b parameter
c.test(5);
// call test2 function with c and b parameters
c.test2(1, 2);
Will get updated soon