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.

Implementers

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
parent → HierarchicalInjector
@protected, final, 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, inherited
injectFromAncestry<T>(Object token) → T
Injects and returns an object representing token from ancestors. [...]
@protected, inherited
injectFromAncestryOptional(Object token, [Object orElse = throwIfNotFound]) Object
Injects and returns an object representing token from ancestors. [...]
@protected, inherited
injectFromParent<T>(Object token) → T
Injects and returns an object representing token from the parent. [...]
@protected, inherited
injectFromParentOptional(Object token, [Object orElse = throwIfNotFound]) Object
Injects and returns an object representing token from the parent. [...]
@protected, inherited
injectFromSelf<T>(Object token) → T
Injects and returns an object representing token from this injector. [...]
@protected, inherited
injectFromSelfOptional(Object token, [Object orElse = throwIfNotFound]) Object
Injects and returns an object representing token from this injector. [...]
@protected, inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
provideToken<T>(OpaqueToken<T> token) → T
Finds and returns an object instance provided for a token. [...]
inherited
provideTokenOptional<T>(OpaqueToken<T> token) → T
Finds and returns an object instance provided for a token. [...]
inherited
provideType<T extends Object>(Type token) → T
Finds and returns an object instance provided for a type token. [...]
inherited
provideTypeOptional<T extends Object>(Type token) → T
Finds and returns an object instance provided for a type token. [...]
inherited
provideUntyped(Object token, [Object orElse = throwIfNotFound]) Object
Injects and returns an object representing token. [...]
@protected, inherited
toString() String
A string representation of this object. [...]
inherited

Operators

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