diman
v1.1.0
Published
Small Dependency Injection management library
Downloads
4
Maintainers
Readme
diman
Small Dependency Injection management library
Install
$ npm install --save diman
Usage
Simple Injection
var di = require('diman');
function Service(configuration) {
this.configuration = configuration;
}
di.annotate(Service, new di.Inject(Configuration));
function Configuration(){
this.database = 'mongo';
}
var injector = new di.Injector([]);
var service = injector.get(Service);
console.log( service.configuration.database ); //'mongo'
Mocked Injection
function Service(configuration) {
this.configuration = configuration;
}
di.annotate(Service, new di.Inject(Configuration));
function Configuration(){
this.database = 'mongo';
}
function DevConfiguration(){
this.database = 'dev-mongo';
}
di.annotate(DevConfiguration, new di.Provide(Configuration));
var injector = new di.Injector([DevConfiguration]);
var service = injector.get(Service);
console.log( service.configuration.database ); //'dev-mongo'
License
MIT © Avag Arakelyan