This package has been deprecated

Author message:

This package migrated to @ts-stack/di.

ts-di
TypeScript icon, indicating that this package has built-in type declarations

2.3.0 • Public • Published

Build Status

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:

{
  "compilerOptions": {
    // ...
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Example usage

import 'reflect-metadata';
import { ReflectiveInjector, Injectable } from 'ts-di';
 
@Injectable()
class UsefulService {
}
 
@Injectable()
class NeedsService {
  constructor(public service: UsefulService) {}
}
 
const injector = ReflectiveInjector.resolveAndCreate([NeedsService, UsefulService]);
const needsService = injector.get(NeedsService);
expect(needsService instanceof NeedsService).toBe(true);
expect(needsService.service instanceof UsefulService).toBe(true);

For more examples, see the tests for ts-di.

API

For full documentation check Angular DI docs:

Dependents (0)

Package Sidebar

Install

npm i ts-di

Weekly Downloads

22

Version

2.3.0

License

MIT

Unpacked Size

156 kB

Total Files

67

Last publish

Collaborators

  • ktretiak