Fundamentals - Dependency Injection V

Resolvers:

- The DI container uses Resolvers internally to provide all instances. 
- When explicitly configuring the container, you are actually specifying what Resolver should be associated with a particular lookup key. However, there's a second way that resolvers are useful. Instead of supplying a key as part of the inject decorator, you can provide a Resolver instead. This resolver then communicates with the container to provide special resolution behavior, specific to the injection.

Lazy - Injects a function for lazily evaluating the dependency.
        ex. Lazy.of(HttpClient)

All - Injects an array of all services registered with the provided key.
        ex. All.of(Plugin)

Optional - Injects an instance of a class only if it already exists in the container; null otherwise.
        ex. Optional.of(LoggedInUser)

Parent - Skips starting dependency resolution from the current container and instead begins the lookup process on the parent container.
        ex. Parent.of(MyCustomElement)

Factory - Used to allow injecting dependencies, but also passing data to the constructor.
        ex. Factory.of(CustomClass)

NewInstance
- Used to inject a new instance of a dependency, without regard for existing instances in the container.
        ex. NewInstance.of(CustomClass).as(Another)

In TypeScript, @autoinject won't allow to use Resolvers

Comments

Popular posts from this blog

Fundamentals - App Config & Startup - VIII

Style vs Css attribute