1.0.0 • Published 6 years ago
simple-dependency-injector v1.0.0
Use decorators to manage dependency injection in you TS and JS projects
Installation
npm install simple-dependency-injector --save
yarn add simple-dependency-injector
this module need experimentalDecorators enabled
Usage
Use @Injectable
to declare an injectable object.
Use @Inject([<injectable constructor>,])
to inject declared injectable into a function.
TypeScript
import {Injectable, Inject} from "simple-dependency-injector";
@Injectable
class MyInjectable {
//some code
}
@Inject([MyInjectable])
class WhoNeedMyInjectable {
constructor(private myInjectable: MyInjectable) {
//use MyInjectable with this.myInjectable
}
}
Javascript
import {Injectable, Inject} from "simple-dependency-injector";
@Injectable
class MyInjectable {
//some code
}
@Inject([MyInjectable])
class WhoNeedMyInjectable {
constructor(myInjectable) {
this.myInjectable = myInjectable;
//use MyInjectable with this.myInjectable
}
}
Test
npm run test