DIConfiguration
Usage
import { DIConfiguration } from "@tsed/di";Overview
class DIConfiguration {
readonly default: Map<string, any>;
protected map: Map<string, any>;
constructor(initialProps?: {});
get version(): string;
set version(v: string);
get rootDir(): string;
set rootDir(value: string);
get env(): Env;
set env(value: Env);
get imports(): (TokenProvider | ImportTokenProviderOpts)[];
set imports(imports: (TokenProvider | ImportTokenProviderOpts)[]);
get lazyProviders(): boolean;
set lazyProviders(lazyProviders: boolean);
get routes(): TokenRoute[];
set routes(routes: TokenRoute[]);
get logger(): Partial<DILoggerOptions>;
set logger(value: Partial<DILoggerOptions>);
get debug(): boolean;
set debug(debug: boolean);
get mount(): Record<string, TokenProvider[]>;
set mount(value: Record<string, TokenProvider[]>);
forEach(callbackfn: (value: any, index: string, map: Map<string, any>) => void, thisArg?: any): void;
set(obj: Partial<TsED.Configuration>): this;
set(propertyKey: string, value?: unknown): this;
setRaw(propertyKey: string, value: any): this;
get<T = any>(propertyKey: string, defaultValue?: T): T;
decorate(key: string, value: ((...args: unknown[]) => unknown) | PropertyDescriptor): this | undefined;
protected getRaw(propertyKey: string, defaultValue?: any): any;
}Description
Configuration management service for the DI system.
Stores and manages application configuration settings including imports, routes, logger options, and custom properties. Provides type-safe accessors for common configuration keys and supports nested property access via get() and set().
Usage
import {DIConfiguration} from "@tsed/di";
const config = new DIConfiguration({
rootDir: __dirname,
env: Env.PROD,
logger: {level: "info"}
});
config.set("custom.nested.key", "value");
const value = config.get("custom.nested.key");Constructor
constructor(initialProps?: {});Creates a configuration service with the built-in defaults merged with the supplied initial properties.
readonly default
readonly default: Map<string, any>;protected map
protected map: Map<string, any>;get version
get version(): string;Gets the application version.
set version
set version(v: string);Sets the application version.
get rootDir
get rootDir(): string;Gets the application's root directory.
set rootDir
set rootDir(value: string);Sets the application's root directory.
get env
get env(): Env;Gets the active runtime environment.
set env
set env(value: Env);Sets the active runtime environment.
get imports
get imports(): (TokenProvider | ImportTokenProviderOpts)[];Gets the providers and modules imported by the application.
set imports
set imports(imports: (TokenProvider | ImportTokenProviderOpts)[]);Sets the providers and modules imported by the application.
get lazyProviders
get lazyProviders(): boolean;Indicates whether synchronous singleton providers without hooks are deferred until first use.
set lazyProviders
set lazyProviders(lazyProviders: boolean);Enables or disables deferred initialization of synchronous singleton providers without hooks.
get routes
get routes(): TokenRoute[];Gets the route providers registered by the application.
set routes
set routes(routes: TokenRoute[]);Sets the route providers registered by the application.
get logger
get logger(): Partial<DILoggerOptions>;Gets the logger options.
set logger
set logger(value: Partial<DILoggerOptions>);Merges logger options into the current logger configuration.
get debug
get debug(): boolean;Indicates whether the logger is configured at the debug level.
set debug
set debug(debug: boolean);Enables or disables debug-level logging.
get mount
get mount(): Record<string, TokenProvider[]>;Gets route providers grouped by mount path.
set mount
set mount(value: Record<string, TokenProvider[]>);Sets route providers grouped by mount path.
forEach
forEach(callbackfn: (value: any, index: string, map: Map<string, any>) => void, thisArg?: any): void;callbackfn (
(value: any): Callback invoked with the resolved value, key, and override map.thisArg (
any): Optional. Value to use asthiswhen invoking the callback.
Invokes a callback once for each configured key, including default and overridden values.
set
set(obj: Partial<TsED.Configuration>): this;propertyKey (``): Configuration key and value, or an object containing multiple values.
value (``): Value to assign when
propertyKeyis a string.
Sets one or more configuration values.
Property names matching a configuration accessor are delegated to that accessor; other keys support nested paths.
set
set(propertyKey: string, value?: unknown): this;setRaw
setRaw(propertyKey: string, value: any): this;propertyKey (
string): Configuration key or nested property path.value (
any): Value to store.
Sets a configuration value directly in the override map, supporting nested property paths.
get
get<T = any>(propertyKey: string, defaultValue?: T): T;propertyKey (
string): Configuration key or nested property path.defaultValue (
T): Optional. Value to return when neither the overrides nor defaults define the key.
Gets a resolved configuration value, preferring explicit overrides over default values.
decorate
decorate(key: string, value: ((...args: unknown[]) => unknown) | PropertyDescriptor): this | undefined;key (
string): Name of the member to define.value (
((...args: unknown[]) => unknown)|PropertyDescriptor): Function or property descriptor to assign to the configuration prototype.
Defines a custom configuration member when a member with the same key does not already exist.
protected getRaw
protected getRaw(propertyKey: string, defaultValue?: any): any;propertyKey (
string): Configuration key or nested property path.defaultValue (
any): Optional. Value to return when no configured value exists.
Resolves a configuration value from overrides, defaults, or the supplied fallback in that order.