Dependency injection library for JavaScript and TypeScript. It is an extraction of the Angular's dependency injection which means that it's feature complete, fast, reliable and well tested. Also - retrieve all API documentation with example code.
Up-to-date with Angular 4.4.7, but with support DI to inherited class (when the child class does not have a constructor, while the parent class has it), and with exported makeDecorator()
, makeParamDecorator()
, makePropDecorator()
, reflector
, Type
(see reflector test).
Install
npm i ts-di
Also you need to install reflect-metadata
module:
npm i reflect-metadata
Then, in tsconfig.json
file, for compilerOptions
you need to set experimentalDecorators
and emitDecoratorMetadata
to true
:
Example usage
;; ;;expectneedsService instanceof NeedsService.toBetrue;expectneedsService.service instanceof UsefulService.toBetrue;
For more examples, see the tests for ts-di.
API
For full documentation check Angular DI docs: