DIContext
@tsed/di
Usage
typescript
import { DIContext } from "@tsed/di";
Overview
ts
class DIContext {
opts: DIContextOptions;
[x: string]: any;
readonly PLATFORM: string;
constructor(opts: DIContextOptions);
get logger(): ContextLogger;
get id(): string;
get dateStart(): Date;
get injector(): InjectorService;
get env(): any;
get container(): LocalsContainer;
destroy(): Promise<any>;
cache<Value = any>(key: string, cb: () => Value): Value;
cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value>;
delete(key: any): boolean;
get<T = any>(key: any): T;
has(key: any): boolean;
set(key: any, value: any): this;
}
opts
ts
opts: DIContextOptions;
[x: string]
ts
[x: string]: any;
readonly PLATFORM
ts
readonly PLATFORM: string;
get logger
ts
get logger(): ContextLogger;
Logger attached to the context request.
get id
ts
get id(): string;
Request id generated by contextMiddleware.
TIP
By default Ts.ED generate uuid like that uuidv4().replace(/-/gi, ""))
. Dash are removed to simplify tracking logs in Kibana
TIP
Request id can by customized by changing the server configuration.
typescript
@Configuration({
logger: {
reqIdBuilder: createUniqId // give your own id generator function
}
})
class Server {
}
get dateStart
ts
get dateStart(): Date;
get injector
ts
get injector(): InjectorService;
get env
ts
get env(): any;
get container
ts
get container(): LocalsContainer;
The request container used by the Ts.ED DI. It contains all services annotated with @Scope(ProviderScope.REQUEST)
destroy
ts
destroy(): Promise<any>;
cache
ts
cache<Value = any>(key: string, cb: () => Value): Value;
cacheAsync
ts
cacheAsync<Value = any>(key: string, cb: () => Promise<Value>): Promise<Value>;
delete
ts
delete(key: any): boolean;
get
ts
get<T = any>(key: any): T;
has
ts
has(key: any): boolean;
set
ts
set(key: any, value: any): this;