Injector class abstract

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

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

get(Object token, [Object? notFoundValue = throwIfNotFound]) → dynamic
Returns an instance from the injector based on the provided token.
injectFromAncestry<T>(Object token) → T
Injects and returns an object representing token from ancestors.
injectFromAncestryOptional(Object token, [Object? orElse = throwIfNotFound]) Object?
Injects and returns an object representing token from ancestors.
injectFromParent<T>(Object token) → T
Injects and returns an object representing token from the parent.
injectFromParentOptional(Object token, [Object? orElse = throwIfNotFound]) Object?
Injects and returns an object representing token from the parent.
injectFromSelf<T>(Object token) → T
Injects and returns an object representing token from this injector.
injectFromSelfOptional(Object token, [Object? orElse = throwIfNotFound]) Object?
Injects and returns an object representing token from this injector.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
provideToken<T extends Object>(OpaqueToken<T> token) → T
Finds and returns an object instance provided for a token.
provideTokenOptional<T extends Object>(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<T>(Object token, [Object? orElse = throwIfNotFound]) → T
Injects and returns an object representing token.
toString() String
A string representation of this object.
inherited

Operators

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