ng_di

Build Status

A Dependency Injection package taken from angular DI.

Usage

  1. create a file tool/build.dart and add next code:

{@example tool/build.dart}

  1. create one of the examples shown below

  2. run tool/build.dart

Inject by Type

In this case you need to annotate classes with @Injectable() or @injectable. This annotation tells to library built-mirrors to generate respective mirrors. For example:

{@example example/type.dart}

Inject using @Inject() annotation

In this case you can specify the token corresponding to the dependency that will be injected. For example:

{@example example/inject.dart}

Inject using @Optional() or @optional annotation

In this case we can mark dependencies as optional, so if the value is not injected then a null value is passed. For example:

{@example example/optional.dart}

Inject using @Self() or @self annotation

In this case we can mark dependencies as self, so the injector should retrieve a dependency only from itself. For example:

{@example example/self.dart}

Inject using @SkipSelf() or @skipSelf annotation

In this case we can mark dependencies as optional, so the dependency resolution should start from the parent injector. For example:

{@example example/skip_self.dart}

Libraries

ng_di