This fork - it's just version TypeScript Angular di.js.
npm install ts-di --save
Inject instance of class A
for constructor of class B
:
import {Inject} from 'ts-di';
class A{}
// All dependencies in @Inject listed separated by commas
@Inject(A)
class B
{
constructor(private a: A){}
getValue()
{
console.log(`There should be a instance of class A:`, this.a);
}
}
import {annotate, InjectDecorator} from 'ts-di';
class A{}
class B
{
constructor(private a: A){}
getValue()
{
console.log(`There should be a instance of class A:`, this.a);
}
}
// All dependencies in InjectDecorator listed separated by commas
annotate( B, new InjectDecorator(A) );
import {Injector} from 'ts-di';
import {B} from './path/to/class/B';
let injector = new Injector();
// Instance class B and resolve dependency
let instance = injector.get(B);
Now supports five decorators:
- For resolving chain dependencies:
@Inject
@InjectPromise
@InjectLazy
- For resolving single dependency (useful for testing):
@Provide
@ProvidePromise