[](https://travis-ci.com/alexandruluca/typescript-di-container)
npm install typescript-di-container
You will need to add followin lines to your tsconfig.json file
```
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
`
import {Container, Injectable} from 'typescript-di-container';
const container = new Container();
@Injectable()
class CacheService {
constructor() {
}
}
@Injectable()
class AuthRouter {
cacheService: CacheService
constructor(cacheService: CacheService) {
this.cacheService = cacheService
}
}
let authRouter = container.get(AuthRouter);
`
`
import {Injectable, Inject, ForwardRef, Container} from 'typescript-di-container';
@Injectable()
class D {
constructor(@Inject(new ForwardRef(() => E)) e: E) {}
}
@Injectable()
class E {
constructor(d: D) {}
}
const container = new Container();
const a = container.get(D);
// will throw error => Circular dependency detected: D -> E -> D
`
In order to overcome this problem, one can use ForwardRef, like so
`
import {Injectable, Inject, ForwardRef, Container} from 'typescript-di-container';
@Injectable()
class D {
constructor(@Inject(new ForwardRef(() => E)) e: E) {}
}
@Injectable()
class E {
constructor(d: D) {}
}
const container = new Container();
const a = container.get(D);
``