Private ReadonlycontainerPrivate ReadonlycontainerPrivate ReadonlyfactoriesPrivate ReadonlyinstancesPrivate ReadonlyloggerPrivate Optional ReadonlyparentPrivate ReadonlyprovidersPrivate ReadonlyresolvePrivate ReadonlyservicePrivate ReadonlyservicesPrivate ReadonlyserviceWrap all instance created by this container in Proxies. When set to true each service instance created by this container is wrapped in
a Proxy
For now the recommended setting is false unless you need to dynamically swap service instances without recreated the dependencies that use them.
For circular references proxies will always be used even when useInstanceProxies is set to false
Static ReadonlyrootGlobal root container; by default all services are contained in there
Returns true if this container is the root container of the application. The root container is the container that is created
by default and contains all services by default.
StaticscopeGet's the current container instance from which dependencies are resolved. Set during resolution phase allowing child entities to be resolved from the same context as their parent.
Register a new service instance or type in this container. If the added entity is an instance it will be treated as singleton even if the lifecycle is transient.
the service instance
Optionaloptions: Partial<ServiceOptions & { provides: ObjectType<T>[] }>optional service options
PrivateaddOptionaloptions: Partial<ServiceOptions & { provides: ObjectType<T>[] }>PrivateaddOptionaloptions: Partial<ServiceOptions & { provides: ObjectType<I>[] }>Create a new container that inherits all configuration form the parent but on top of that can register or overwrite dependencies; by default dependency resolution is first attempted using the providers, factories and registered service instance in the new container; if that fails it resolution is delegated to the parent until the root container which will throw an exception in case it cannot resolve the requested module.
Optionaloptions: { isolated?: boolean }PrivatecreateCreates a new instance of the specified type resolving dependencies using the current container context. The returned class is not registered in the container as dependency.
Constructor type/prototype class definition
Decorates a class type with additional metadata for dependency injection.
Constructor type to decorate
Decorated constructor type
PrivatedecorateDispose all services; factories and provides in this container.
PrivategenerateSafe version of Container.resolve that never returns undefined and throws an Error for services that cannot be resolved.
Service type for which to resolve the concrete class
Internal function to get the property descriptor for an injectable property; used by the inject decorator.
Key of the property to get the descriptor for
Defined property descriptor
PrivategetOptionalproperty: string | symbolPrivategetOptionalproperty: string | symbolPrivategetPrivategetPrivategetPrivategetCreate a new instance of a type resolving constructor parameters as dependencies using the container. The returned class is not added in the container even when the lifecycle policy is singleton.
New instance of an object who's dependencies are resolved by the container
Create a new instance of the given type, with construction wrapped in a deferred initializer.
The type and any provided partial constructor arguments are forwarded to the container's
createInstance method. The actual construction is wrapped with lazy(...) so the creation logic
is executed by the lazy initializer; this method invokes that initializer and returns the created
instance.
The constructor type to instantiate.
The constructed instance of the specified constructor type.
Register a factory that can provide an instance of the specified factory
list of services to register
factory that produces the an instance
Register a service proxy that can be manually set with a concrete instance later on. Any instance that request a service of type T will receive the proxy instance.
The proxy is not registered as a factory type.
The proxy instance can be set using the setInstance method on the ProxyTarget returned by this method.
Service type to register
ProxyTarget instance that can be used to set the concrete instance
Drops an active singleton service instance from the container causing subsequent resolutions to create a new instances instead of reusing the existing one.
the instance to remove
Resolve requested type to a concrete implementation.
Service type for which to resolve a concrete class
Optionalreceiver: new (...args: any[]) => objectClass ctor for which we are resolving this
Resolve injectable parameters for a service using this container.
Constructor function
arguments
OptionalinstanceGuid: stringinstance guid
Resolve a single property on an instance
The instance containing the property
The name of the property to resolve
Optionaloptions: { trackAsDependency?: boolean }The resolved property value
PrivatetrackRegister a new dependency between two services
the instance guid of the object that owns the dependency
instance of the dependency
Use the specified instance to provided the specified service types. If an existing service is already registered for a type, it will be replaced with the new instance.
the service instance
Optionaltypes: ObjectType<object> | ObjectType<object>[]the service types to provide
StaticgetGet's the container that owns or created the specified instance.
The DI container can be used to register and resolve dependencies automatically. It supports constructor injection and property injection of dependencies. There are two built-in lifecycle policies: LifecyclePolicy.singleton and LifecyclePolicy.transient.
The DI framework uses two decorators to mark classes and properties as injectable:
When creating a class through the container, constructor parameters will automatically be resolved by type. When creating a class outside of the container, constructor parameters will not be resolved.
Injectable properties are resolved lazily when they are first accessed and are cached for subsequent access on a unique symbol on the instance for which they are resolved. Resolution of injectable properties uses the container that created the instance. If the instance was created outside of a container, the root container is used to try and resolve the dependency.
When the container cannot resolve a dependency it will return
undefinedfor properties and constructor parameters marked with inject decorator.The DI framework requires the following tsconfig settings to be enabled:
emitDecoratorMetadata: true(required to emit type metadata for decorated classes and properties)experimentalDecorators: true(required to use decorators at all)useDefineForClassFields: false(required in order to use inject)@example: