Class Overview
class ReflectiveInjector implements Injector {
staticresolve
(providers: Provider[]) : ResolvedReflectiveProvider[]
staticresolveAndCreate
(providers: Provider[], parent?: Injector) : ReflectiveInjector
staticfromResolvedProviders
(providers: ResolvedReflectiveProvider[], parent?: Injector) : ReflectiveInjector
parent
: Injector
resolveAndCreateChild
(providers: Provider[]) : ReflectiveInjector
createChildFromResolved
(providers: ResolvedReflectiveProvider[]) : ReflectiveInjector
resolveAndInstantiate
(provider: Provider) : any
instantiateResolved
(provider: ResolvedReflectiveProvider) : any
get
(token: any, notFoundValue?: any) : any
}
Class Description
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
.
Example (live demo)
The following example creates an Injector
configured to create Engine
and Car
.
Notice, we don't use the new
operator because we explicitly want to have the Injector
resolve all of the object's dependencies automatically.
Static Members
resolve(providers: Provider[]) : ResolvedReflectiveProvider[]
Turns an array of provider definitions into an array of resolved providers.
A resolution is a process of flattening multiple nested arrays and converting individual
providers into an array of ResolvedReflectiveProvider
s.
See ReflectiveInjector
for more info.
resolveAndCreate(providers: Provider[], parent?: Injector) : ReflectiveInjector
Resolves an array of providers and creates an injector from those providers.
The passed-in providers can be an array of Type
, Provider
,
or a recursive array of more providers.
This function is slower than the corresponding fromResolvedProviders
because it needs to resolve the passed-in providers first.
See Injector
and Injector
.
fromResolvedProviders(providers: ResolvedReflectiveProvider[], parent?: Injector) : ReflectiveInjector
Creates an injector from previously resolved providers.
This API is the recommended way to construct injectors in performance-sensitive parts.
Class Details
parent : Injector
Parent of this injector.
resolveAndCreateChild(providers: Provider[]) : ReflectiveInjector
Resolves an array of providers and creates a child injector from those providers.
The passed-in providers can be an array of Type
, Provider
,
or a recursive array of more providers.
This function is slower than the corresponding createChildFromResolved
because it needs to resolve the passed-in providers first.
See Injector
and Injector
.
createChildFromResolved(providers: ResolvedReflectiveProvider[]) : ReflectiveInjector
Creates a child injector from previously resolved providers.
This API is the recommended way to construct injectors in performance-sensitive parts.
resolveAndInstantiate(provider: Provider) : any
Resolves a provider and instantiates an object in the context of the injector.
The created object does not get cached by the injector.
instantiateResolved(provider: ResolvedReflectiveProvider) : any
Instantiates an object using a resolved provider in the context of the injector.
The created object does not get cached by the injector.
get(token: any, notFoundValue?: any) : any
exported from @angular/core/index, defined in @angular/core/src/di/reflective_injector.ts