Injector class

Support for imperatively loading dependency injected services at runtime.

Injector is a simple interface that accepts a valid token (often either a Type or OpaqueToken, but can be a custom object that respects equality based on identity), and returns an instance for that token.

WARNING: It is not supported to sub-class this type in your own applications. There are hidden contracts that are not implementable by client code. If you need a mock-like implementation of Injector instead prefer using Injector.map.

Constructors

Injector()
const
Injector.empty([HierarchicalInjector parent ])
Creates an injector that has no providers. [...]
const
factory
Injector.map(Map<Object, Object> providers, [ HierarchicalInjector parent ])
Create a new Injector that uses a basic map of token->instance. [...]
const
factory

Properties

hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

get(Object token, [ Object notFoundValue = throwIfNotFound ]) → dynamic
Returns an instance from the injector based on the provided token. [...]
@mustCallSuper
provideToken<T>(OpaqueToken<T> token) → T
Finds and returns an object instance provided for a token. [...]
provideTokenOptional<T>(OpaqueToken<T> token) → T
Finds and returns an object instance provided for a token. [...]
provideType<T extends Object>(Type token) → T
Finds and returns an object instance provided for a type token. [...]
provideTypeOptional<T extends Object>(Type token) → T
Finds and returns an object instance provided for a type token. [...]
provideUntyped(Object token, [ Object orElse ]) → Object
Injects and returns an object representing token. [...]
@protected
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited