Container · Core API
type Container = object;Container that stores providers and resolves typed dependencies.
Methods
Section titled “Methods”register()
Section titled “register()”register(provider, options?): void;Registers a provider in this container.
Pass { allowOverride: true } to intentionally replace an existing
provider for the same token.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
|
|
Returns
Section titled “Returns”void
Throws
Section titled “Throws”DuplicateProviderError when the token is already registered.
Throws
Section titled “Throws”InvalidProviderError when overriding a live disposable instance.
Call Signature
Section titled “Call Signature”get<T>(token): T;Resolves a required token.
Throws MissingProviderError when no provider exists in this container or
any parent container.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”T
Throws
Section titled “Throws”MissingProviderError when no provider exists.
Throws
Section titled “Throws”CircularDependencyError when the dependency graph contains a cycle.
Throws
Section titled “Throws”InvalidProviderError when provider lifetimes are incompatible.
Call Signature
Section titled “Call Signature”get<T>(dependency): T | undefined;Resolves an optional dependency.
Returns undefined when no provider exists in this container or any parent
container.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
|
|
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
Returns
Section titled “Returns”T | undefined
has(token): boolean;Checks whether this container or one of its parents has a provider.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
|
|
|
Returns
Section titled “Returns”boolean
dispose()
Section titled “dispose()”dispose(): Promise<void>;Disposes cached instances owned by this container.
Disposal hooks run in reverse creation order. Calling dispose more than
once is safe.
Returns
Section titled “Returns”Promise<void>