This library was inpired by AngularJS
npm i inject-dependency
import {Context, singleton, injectable, dependencies, lazyInject, fabrica} from 'inject-dependency'
@singleton
@injectable()
class A {
@lazyInject<C>('C', a => a.c.hello())
c: C;
hello() {
console.log('A');
}
}
@singleton
@dependencies(A)
@injectable()
class B {
constructor(public a: A) {}
hello() {
console.log('B');
}
}
@singleton
@dependencies(B)
@injectable('C')
class C {
constructor(public b: B) {}
hello() {
console.log('C');
}
}
const cInstance = Context.resolve<C>(C);
cInstance.b.a.hello();
cInstance.b.hello();
cInstance.hello();
/*
A
B
C
C
*/
import {Context, singleton, injectable, dependencies, lazyInject, fabrica} from 'inject-dependency'
@singleton
@injectable()
class A {
@lazyInject('C', a => a.c.hello())
c;
hello() {
console.log('A');
}
}
@singleton
@dependencies(A)
@injectable()
class B {
constructor(a) {
this.a = a
}
hello() {
console.log('B');
}
}
@singleton
@dependencies(B)
@injectable('C')
class C {
constructor(b) {
this.b = b
}
hello() {
console.log('C');
}
}
const cInstance = Context.resolve(C);
cInstance.b.a.hello();
cInstance.b.hello();
cInstance.hello();
/*
A
B
C
C
*/
class decorator
class decorator
class decorator
property decorator
class decorator
Generated using TypeDoc