A ReflectiveDependency injection container used for instantiating objects and resolving dependencies.
An Injector is a replacement for a new
operator, which can automatically
resolve the constructor dependencies.
In typical use, application code asks for the dependencies in the constructor and they are resolved by the Injector.
The following example creates an Injector
configured to create Engine
and Car
.
@Injectable()
class Engine {
}
@Injectable()
class Car {
Car(Engine engine);
}
var injector = ReflectiveInjector.resolveAndCreate([Car, Engine]);
var car = injector.get(Car);
expect(car is Car, true);
expect(car.engine is Engine, true);
Notice, we don't use the new
operator because we explicitly want to have
the Injector resolve all of the object's dependencies automatically.
- Implements
-
- Injector
Static Methods
-
fromResolvedBindings(
List<ResolvedReflectiveProvider> providers) → ReflectiveInjector -
fromResolvedProviders(
List<ResolvedReflectiveProvider> providers, [ Injector parent = null ]) → ReflectiveInjector -
Creates an injector from previously resolved providers.
-
resolve(
List providers) → List<ResolvedReflectiveProvider> -
Turns an array of provider definitions into an array of resolved providers.
-
resolveAndCreate(
List providers, [ Injector parent = null ]) → ReflectiveInjector -
Resolves an array of providers and creates an injector from those providers.
Constructors
Properties
- hashCode → int
-
Get a hash code for this object.
read-only, inherited - parent → Injector
-
Parent of this injector.
read-only - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
createChildFromResolved(
List<ResolvedReflectiveProvider> providers) → ReflectiveInjector -
Creates a child injector from previously resolved providers.
-
debugContext(
) → dynamic -
get(
token, [ notFoundValue ]) → dynamic -
Retrieves an instance from the injector based on the provided token. If not found: - Throws
NoProviderError
if nonotFoundValue
that is not equal to Injector.THROW_IF_NOT_FOUND is given - Returns thenotFoundValue
otherwise -
instantiateResolved(
ResolvedReflectiveProvider provider) → dynamic -
Instantiates an object using a resolved provider in the context of the injector.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
resolveAndCreateChild(
List providers) → ReflectiveInjector -
Resolves an array of providers and creates a child injector from those providers.
-
resolveAndInstantiate(
provider) → dynamic -
Resolves a provider and instantiates an object in the context of the injector.
-
toString(
) → String -
Returns a string representation of this object.
inherited