Provider
@tsed/di
Usage
typescript
import { Provider } from "@tsed/di";
Overview
ts
class Provider<T = any> implements ProviderOpts<T> {
type: ProviderType | TokenProvider;
deps: TokenProvider[];
imports: (TokenProvider | [TokenProvider])[];
alias: string;
priority: number;
useFactory?: Function;
useAsyncFactory?: Function;
useValue?: unknown;
hooks: Record<string, ProviderHookCallback<T>>;
[key: string]: any;
constructor(token: TokenProvider<T>, options?: Partial<Provider>);
get token(): TokenProvider;
set token(value: TokenProvider);
get provide(): TokenProvider;
set provide(value: TokenProvider);
get useClass(): Type<T>;
set useClass(value: Type<T> | AbstractType<T>);
get className(): string;
get name(): string;
get store(): Store;
get path(): string;
set path(path: string);
get scope(): ProviderScope;
set scope(scope: ProviderScope);
get configuration(): Partial<TsED.Configuration>;
set configuration(configuration: Partial<TsED.Configuration>);
get children(): TokenProvider[];
set children(children: TokenProvider[]);
getArgOpts(index: number): any;
get<Type = unknown>(key: string): Type | undefined;
get<Type = unknown>(key: string, defaultValue: Type): Type;
isAsync(): boolean;
clone(): Provider;
hasChildren(): boolean;
hasParent(): boolean;
toString(): string;
}
type
ts
type: ProviderType | TokenProvider;
Token group provider to retrieve all provider from the same type
deps
ts
deps: TokenProvider[];
imports:
ts
imports: (TokenProvider | [TokenProvider])[];
alias
ts
alias: string;
priority
ts
priority: number;
useFactory
ts
useFactory?: Function;
useAsyncFactory
ts
useAsyncFactory?: Function;
useValue
ts
useValue?: unknown;
hooks
ts
hooks: Record<string, ProviderHookCallback<T>>;
[key: string]
ts
[key: string]: any;
get token
ts
get token(): TokenProvider;
set token
ts
set token(value: TokenProvider);
get provide
ts
get provide(): TokenProvider;
set provide
ts
set provide(value: TokenProvider);
get useClass
ts
get useClass(): Type<T>;
set useClass
ts
set useClass(value: Type<T> | AbstractType<T>);
Create a new store if the given value is a class. Otherwise, the value is ignored.
get className
ts
get className(): string;
get name
ts
get name(): string;
get store
ts
get store(): Store;
get path
ts
get path(): string;
set path
ts
set path(path: string);
get scope
ts
get scope(): ProviderScope;
Get the scope of the provider.
Note
Async provider is always a SINGLETON
set scope
ts
set scope(scope: ProviderScope);
Change the scope value of the provider.
get configuration
ts
get configuration(): Partial<TsED.Configuration>;
set configuration
ts
set configuration(configuration: Partial<TsED.Configuration>);
get children
ts
get children(): TokenProvider[];
set children
ts
set children(children: TokenProvider[]);
getArgOpts
ts
getArgOpts(index: number): any;
get
ts
get<Type = unknown>(key: string): Type | undefined;
- key (
string
): The key to look up
Retrieves a value from the provider's store.
get
ts
get<Type = unknown>(key: string, defaultValue: Type): Type;
key (
string
): The key to look updefaultValue (
Type
): The value to return if key is not found
Retrieves a value from the provider's store with a default fallback.
isAsync
ts
isAsync(): boolean;
clone
ts
clone(): Provider;
hasChildren
ts
hasChildren(): boolean;
hasParent
ts
hasParent(): boolean;
toString
ts
toString(): string;