Container
@tsed/di
Usage
typescript
import { Container } from "@tsed/di";
Overview
ts
class Container extends Map<TokenProvider, Provider> {
add(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
addProvider(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
hasProvider(token: TokenProvider): boolean;
setProvider(token: TokenProvider, provider: Provider): this;
getProvider<T extends Provider = Provider>(token: TokenProvider | undefined): T | undefined;
getProviders(type?: TokenProvider | ProviderType | string | string[]): Provider[];
addProviders(container: Map<TokenProvider, Provider>): void;
}
add
ts
add(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
addProvider
ts
addProvider(token: TokenProvider, settings?: Partial<ProviderOpts>): this;
Add a provider to the
hasProvider
ts
hasProvider(token: TokenProvider): boolean;
setProvider
ts
setProvider(token: TokenProvider, provider: Provider): this;
Add a provider to the
getProvider
ts
getProvider<T extends Provider = Provider>(token: TokenProvider | undefined): T | undefined;
The getProvider() method returns a specified element from a Map object.
getProviders
ts
getProviders(type?: TokenProvider | ProviderType | string | string[]): Provider[];
- type (
TokenProvider
|ProviderType
|string
|string[]
): Optional. Filter the list by the given ProviderType.
Get all providers registered in the injector container.
addProviders
ts
addProviders(container: Map<TokenProvider, Provider>): void;