2.3.0 • Published 4 years ago

ts-di v2.3.0

Weekly downloads
21
License
MIT
Repository
github
Last release
4 years ago

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:

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

6 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago