Dependency-Injection

    You can also inject within a RequestContext, as each one has a controller propertythat extends from the app’s global container.

    Accessing these injected properties is easy, and strongly typed:

    In Angel 2.0, by wrapping a function in a call to ioc, you can automaticallyinject the dependencies of any route handler.

    Controllers have dependencies injected without any additional configuration by you. However, you might want to inject dependencies into the constructor of your controller.

    By default, Angel will use the EmptyReflector() to power its instances,which has no support for dart:mirrors, so that it can be used in contexts where Dartreflection is not available.

    However, by using a different Reflector, you can use the full power of Angel’s DI system.angel init projects use the MirrorsReflector() by default.

    The following use cases require reflection:

    • Use of Controllers, via @Expose() or
    • Use of the ioc function in any route

    The MirrorsReflector from package:angel_container/mirrors.dart is by far the most convenient pattern,so use it if possible.

    However, the following alternatives exist:

    • Generation via package:angel_container_generator
    • Manually implementing the interface (cumbersome; not recommended)