1.2.0 • Published 2 years ago

@ts-stack/di v1.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
2 years ago

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(), makePropTypeDecorator(), reflector, Type (see reflector test).

Install

npm i @ts-stack/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-stack/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-stack/di.

API

For full documentation check Angular DI docs:

2.0.0-next.6

1 year ago

2.0.0-next

1 year ago

2.0.0-next.7

1 year ago

2.0.0-next.4

1 year ago

2.0.0-next.5

1 year ago

2.3.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.0.2

1 year ago

2.4.1

1 year ago

2.3.2

1 year ago

2.2.3

1 year ago

2.4.0

1 year ago

2.3.1

1 year ago

2.2.2

1 year ago

2.3.4

1 year ago

2.4.2

1 year ago

2.3.3

1 year ago

2.0.0-beta.2

1 year ago

2.0.0-next.2

1 year ago

2.0.0-beta.1

1 year ago

2.0.0-next.3

1 year ago

2.0.0-next.1

1 year ago

2.0.0-beta.5

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0-beta.4

1 year ago

2.0.0

1 year ago

2.0.0-beta.3

1 year ago

1.2.0

2 years ago

1.2.0-beta.8

3 years ago

1.2.0-rc.2

3 years ago

1.2.0-rc.1

3 years ago

1.2.0-beta.3

3 years ago

1.2.0-beta.2

3 years ago

1.2.0-beta.5

3 years ago

1.2.0-beta.4

3 years ago

1.2.0-beta.7

3 years ago

1.2.0-rc.3

2 years ago

1.2.0-beta.6

3 years ago

1.2.0-beta.1

3 years ago

1.1.0

4 years ago

1.0.0

4 years ago