Readonly
isWhether this container is disposed.
Readonly
optionsThe options used to create this container.
Readonly
parentThe parent container, or undefined
if this is the root container.
Clears and returns all distinct cached values from this container's internal registry. Values from ValueProvider registrations are not included, as they are never cached.
Note that only this container is affected. Parent containers, if any, remain unchanged.
Creates a new child container that inherits this container's options.
You can pass specific options to override the inherited ones.
Optional
options: Partial<ContainerOptions>Disposes this container and all its cached values.
Token values implementing a Disposable
interface (e.g., objects with a dispose()
function)
are automatically disposed during this process.
Note that children containers are disposed first, in creation order.
Returns all cached values associated with registrations of the token, in the order they were registered, or an empty array if none have been cached.
If the token has at least one registration in the current container, cached values are taken from those registrations. Otherwise, cached values may be retrieved from parent containers, if any.
Values are never cached for tokens with transient or resolution scope, or for ValueProvider registrations.
Returns the cached value from the most recent registration of the token,
or undefined
if no value has been cached yet (the token has not been resolved yet).
If the token has at least one registration in this container, the cached value is taken from the most recent of those registrations. Otherwise, it may be retrieved from parent containers, if any.
Values are never cached for tokens with transient or resolution scope, or for ValueProvider registrations.
Returns whether the token is registered in this container or in parent containers, if any.
Registers a ClassProvider, using the class itself as its token.
Tokens provided via the Injectable decorator applied to the class are also registered as aliases.
The scope is determined by the Scoped decorator, if present.
Registers a ClassProvider with a token.
The default registration scope is determined by the Scoped decorator applied to the provided class, if present, but it can be overridden by passing explicit registration options.
Optional
options: RegistrationOptionsRegisters a FactoryProvider with a token.
Optional
options: RegistrationOptionsRegisters an ExistingProvider with a token.
The token will alias the one set in useExisting
.
Registers a ValueProvider with a token.
Values provided via useValue
are never cached (scopes do not apply)
and are simply returned as-is.
Registers one or more tokens as aliases for a target token.
When an alias is resolved, the target token is resolved instead.
Registers a concrete class, where the class acts as its own token.
Tokens provided via the Injectable decorator applied to the class are also registered as aliases.
The default registration scope is determined by the Scoped decorator, if present.
Registers a concrete class with a token.
The default registration scope is determined by the Scoped decorator applied to the class, if present, but it can be overridden by passing explicit registration options.
Optional
options: RegistrationOptionsRegisters a token whose value is produced by a factory function.
The factory function runs inside the injection context and can thus access dependencies via inject-like functions.
Optional
options: RegistrationOptionsRegisters a token with a fixed value.
The provided value is returned as-is when the token is resolved (scopes do not apply).
Removes all registrations from this container's internal registry.
Returns an array of distinct cached values that were stored within the removed registrations. Values from ValueProvider registrations are not included, as they are not cached.
Note that only this container is affected. Parent containers, if any, remain unchanged.
Resolves the given class to the instance associated with it.
If the class is registered in this container or any of its parent containers, an instance is created using the most recent registration.
If the class is not registered, but it is decorated with AutoRegister, or ContainerOptions.autoRegister is true, the class is registered automatically. Otherwise, resolution fails. The scope for the automatic registration is determined by either the Scoped decorator on the class, or ContainerOptions.defaultScope.
If optional
is false or is not passed and the class is not registered in the container
(and could not be auto-registered), an error is thrown.
Otherwise, if optional
is true, undefined
is returned.
The resolution behavior depends on the Provider used during registration:
If the class is registered with container scope, the resolved instance is cached in the container's internal registry.
Optional
optional: falseOptional
optional: booleanResolves the given token to the value associated with it.
If the token is registered in this container or any of its parent containers, its value is resolved using the most recent registration.
If optional
is false or not passed and the token is not registered in the container,
an error is thrown. Otherwise, if optional
is true, undefined
is returned.
The resolution behavior depends on the Provider used during registration:
If the token is registered with container scope, the resolved value is cached in the container's internal registry.
Resolves the given class to all instances provided by the registrations associated with it.
If the class is not registered, but it is decorated with AutoRegister, or ContainerOptions.autoRegister is true, the class is registered automatically. Otherwise, resolution fails. The scope for the automatic registration is determined by either the Scoped decorator on the class, or ContainerOptions.defaultScope.
If optional
is false or is not passed and the class is not registered in the container
(and could not be auto-registered), an error is thrown.
Otherwise, if optional
is true, an empty array is returned.
The resolution behavior depends on the Provider used during registration:
If the class is registered with container scope, the resolved instances are cached in the container's internal registry.
A separate instance of the class is created for each provider.
Optional
optional: falseOptional
optional: booleanResolves the given token to all values provided by the registrations associated with it.
If optional
is false or not passed and the token is not registered in the container,
an error is thrown. Otherwise, if optional
is true, an empty array is returned.
The resolution behavior depends on the Provider used during registration:
If the token is registered with container scope, the resolved values are cached in the container's internal registry.
Removes all registrations for the given token from the container's internal registry.
Returns an array of distinct cached values that were stored within the removed registrations. Values from ValueProvider registrations are not included, as they are not cached.
Note that only this container is affected. Parent containers, if any, remain unchanged.
Container API.