An implementation of the dependency injection helpers at Angular2 (2.0.0 compatible).
Installation
First you need to install the npm module:
npm install angular2-di-helper --save
Use
In general, you don't need configure the providers at the main application module. You have to configure your providers at the main application module only if you use the Singleton annotation.
Use case #1
So, we should integrate the DI module at first.
import{DIModule}from'angular2-di-helper';
@NgModule({
imports:[
DIModule,
...
],
providers:[Action],// Put here your Action if you use the Singleton annotation
...
})
exportclassApplicationModule{
}
Create the Action as a singleton instance via the factory using @Singletondecorator.
import{Singleton}from'angular2-di-helper';
@Singleton()
@Injectable()
exportclassAction{
constructor(...){
}
}
Create the Action2 instance every time as a new instance via the factory.
You have to configure your providers at the main application module using service locator only if you have a "special configuration" of providers, for example:
classDiClass{
constructor(){
}
}
classDiClass1extendsDiClass{
constructor(){
super();
}
methodOfClass1():void{
console.log('Method is called');
}
}
@NgModule({
imports:[DIModule,...],
providers:[]// Empty providers section at the main application module!