Skip to content
Buy me a coffee

Service lifetimes

The lifetime decides how often the container creates a service and who gets the same instance.

Lifetime Register with Instances Owned and disposed by .NET
Singleton addSingleton One per root provider, shared by every scope Root provider AddSingleton
Scoped addScoped One per scope The scope AddScoped
Transient addTransient A new one on every resolution The provider or scope that resolved it AddTransient

The widget below runs the real library. Create scopes, resolve each lifetime and watch which instances are shared: same number, same object. Dispose a scope to see the order in which onDestroy runs.

Clock singletonUnitOfWork scopedRequest transient

root provider

    Event log

    buildServiceProvider({ validateScopes: true })

    Hover an instance to see everywhere it is shared. Each row is one resolution: the service and the instances injected into it.

    One instance for the whole application. Every scope gets the same object. Use it for stateless services and for expensive shared resources: connection pools, HTTP clients, caches, configuration.

    class
    class ConnectionPool
    ConnectionPool
    {}
    const
    const provider: ServiceProvider
    provider
    = new
    new ServiceCollection(): ServiceCollection

    Collects service registrations, then builds a

    ServiceProvider

    . Modeled on .NET's IServiceCollection.

    @example

    const services = new ServiceCollection();
    services.addSingleton(Logger, ConsoleLogger);
    services.addScoped(UserService, [Logger]);
    const provider = services.buildServiceProvider({ validateScopes: true });

    ServiceCollection
    ().
    ServiceCollection.addSingleton<ConnectionPool>(token: Newable<ConnectionPool, []>): ServiceCollection (+4 overloads)

    Registers a singleton: one instance for the root provider and all its scopes.

    • addSingleton(Class) / addSingleton(Class, [deps]): the class is its own token.
    • addSingleton(token, Implementation, [deps]): deps are checked against the constructor's parameters.
    • addSingleton(token, (provider) => instance): a factory, may be async.

    addSingleton
    (
    class ConnectionPool
    ConnectionPool
    ).
    ServiceCollection.buildServiceProvider(options?: BuildOptions): ServiceProvider

    Builds the provider. Registrations are copied, so changing this collection afterwards does not affect providers already built.

    buildServiceProvider
    ();
    const
    const a: ConnectionPool
    a
    = await
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.createScope(): ServiceProvider

    Creates a scope: scoped services resolve once per scope. Dispose it when done (or use await using).

    createScope
    ().
    ServiceProvider.getRequiredService<ConnectionPool>(token: Token<ConnectionPool>): Promise<ConnectionPool>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class ConnectionPool
    ConnectionPool
    );
    const
    const b: ConnectionPool
    b
    = await
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.createScope(): ServiceProvider

    Creates a scope: scoped services resolve once per scope. Dispose it when done (or use await using).

    createScope
    ().
    ServiceProvider.getRequiredService<ConnectionPool>(token: Token<ConnectionPool>): Promise<ConnectionPool>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class ConnectionPool
    ConnectionPool
    );
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    (
    const a: ConnectionPool
    a
    ===
    const b: ConnectionPool
    b
    ); // true

    A singleton must be safe to share: no per-request or per-user state.

    One instance per scope. In a server, one scope per request means one instance per request: the right lifetime for a unit of work, a database transaction, the current user or a request ID.

    class
    class UnitOfWork
    UnitOfWork
    {}
    const
    const provider: ServiceProvider
    provider
    = new
    new ServiceCollection(): ServiceCollection

    Collects service registrations, then builds a

    ServiceProvider

    . Modeled on .NET's IServiceCollection.

    @example

    const services = new ServiceCollection();
    services.addSingleton(Logger, ConsoleLogger);
    services.addScoped(UserService, [Logger]);
    const provider = services.buildServiceProvider({ validateScopes: true });

    ServiceCollection
    ().
    ServiceCollection.addScoped<UnitOfWork>(token: Newable<UnitOfWork, []>): ServiceCollection (+4 overloads)

    Registers a scoped service: one instance per scope. Same forms as

    addSingleton

    .

    addScoped
    (
    class UnitOfWork
    UnitOfWork
    ).
    ServiceCollection.buildServiceProvider(options?: BuildOptions): ServiceProvider

    Builds the provider. Registrations are copied, so changing this collection afterwards does not affect providers already built.

    buildServiceProvider
    ();
    const
    const scope1: ServiceProvider
    scope1
    =
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.createScope(): ServiceProvider

    Creates a scope: scoped services resolve once per scope. Dispose it when done (or use await using).

    createScope
    ();
    const
    const scope2: ServiceProvider
    scope2
    =
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.createScope(): ServiceProvider

    Creates a scope: scoped services resolve once per scope. Dispose it when done (or use await using).

    createScope
    ();
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    ((await
    const scope1: ServiceProvider
    scope1
    .
    ServiceProvider.getRequiredService<UnitOfWork>(token: Token<UnitOfWork>): Promise<UnitOfWork>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class UnitOfWork
    UnitOfWork
    )) === (await
    const scope1: ServiceProvider
    scope1
    .
    ServiceProvider.getRequiredService<UnitOfWork>(token: Token<UnitOfWork>): Promise<UnitOfWork>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class UnitOfWork
    UnitOfWork
    ))); // true
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    ((await
    const scope1: ServiceProvider
    scope1
    .
    ServiceProvider.getRequiredService<UnitOfWork>(token: Token<UnitOfWork>): Promise<UnitOfWork>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class UnitOfWork
    UnitOfWork
    )) === (await
    const scope2: ServiceProvider
    scope2
    .
    ServiceProvider.getRequiredService<UnitOfWork>(token: Token<UnitOfWork>): Promise<UnitOfWork>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class UnitOfWork
    UnitOfWork
    ))); // false

    Resolving a scoped service from the root provider works by default and behaves like a singleton owned by the root. That is almost always a mistake, and validateScopes: true turns it into a ScopeError. See Validation.

    A new instance every time it is resolved, including once per class that depends on it. Use it for lightweight, stateful helpers that must not be shared: builders, parsers, per-operation state.

    class
    class QueryBuilder
    QueryBuilder
    {}
    const
    const provider: ServiceProvider
    provider
    = new
    new ServiceCollection(): ServiceCollection

    Collects service registrations, then builds a

    ServiceProvider

    . Modeled on .NET's IServiceCollection.

    @example

    const services = new ServiceCollection();
    services.addSingleton(Logger, ConsoleLogger);
    services.addScoped(UserService, [Logger]);
    const provider = services.buildServiceProvider({ validateScopes: true });

    ServiceCollection
    ().
    ServiceCollection.addTransient<QueryBuilder>(token: Newable<QueryBuilder, []>): ServiceCollection (+4 overloads)

    Registers a transient service: a new instance on every resolution. Same forms as

    addSingleton

    .

    addTransient
    (
    class QueryBuilder
    QueryBuilder
    ).
    ServiceCollection.buildServiceProvider(options?: BuildOptions): ServiceProvider

    Builds the provider. Registrations are copied, so changing this collection afterwards does not affect providers already built.

    buildServiceProvider
    ();
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    ((await
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getRequiredService<QueryBuilder>(token: Token<QueryBuilder>): Promise<QueryBuilder>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class QueryBuilder
    QueryBuilder
    )) === (await
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getRequiredService<QueryBuilder>(token: Token<QueryBuilder>): Promise<QueryBuilder>

    Resolves token, throwing ServiceNotFoundError if it is not registered.

    getRequiredService
    (
    class QueryBuilder
    QueryBuilder
    ))); // false

    A service lives at most as long as what holds it. A transient injected into a singleton is created once, when the singleton is, and then lives as long as the singleton. That is usually fine. A scoped service injected into a singleton is a bug, a captive dependency: the singleton keeps the first scope’s instance forever. validateScopes catches it.

    Consumer ↓ / dependency → Singleton Scoped Transient
    Singleton ok captive (ScopeError with validateScopes) ok, lives as long as the singleton
    Scoped ok ok, same scope ok
    Transient ok ok, from the resolving scope ok

    Each registration has its own instance. Two registrations of the same token, or of the same class under two tokens, are two services. With getServices, every implementation gets its own singleton (or its own scoped instance per scope).

    class
    class Handler
    Handler
    {}
    const
    const Handlers: InjectionToken<Handler>
    Handlers
    =
    createToken<Handler>(name: string): InjectionToken<Handler>

    Creates a typed token.

    @example

    interface Logger { log(msg: string): void }
    const Logger = createToken<Logger>('Logger');
    services.addSingleton(Logger, ConsoleLogger);
    const logger = await provider.getRequiredService(Logger); // typed as Logger

    createToken
    <
    class Handler
    Handler
    >('Handlers');
    const
    const provider: ServiceProvider
    provider
    = new
    new ServiceCollection(): ServiceCollection

    Collects service registrations, then builds a

    ServiceProvider

    . Modeled on .NET's IServiceCollection.

    @example

    const services = new ServiceCollection();
    services.addSingleton(Logger, ConsoleLogger);
    services.addScoped(UserService, [Logger]);
    const provider = services.buildServiceProvider({ validateScopes: true });

    ServiceCollection
    ()
    .
    ServiceCollection.addSingleton<Handler>(token: Token<Handler>, implementation: Newable<NoInfer<Handler>, []>): ServiceCollection (+4 overloads)

    Registers a singleton: one instance for the root provider and all its scopes.

    • addSingleton(Class) / addSingleton(Class, [deps]): the class is its own token.
    • addSingleton(token, Implementation, [deps]): deps are checked against the constructor's parameters.
    • addSingleton(token, (provider) => instance): a factory, may be async.

    addSingleton
    (
    const Handlers: InjectionToken<Handler>
    Handlers
    ,
    class Handler
    Handler
    )
    .
    ServiceCollection.addSingleton<Handler>(token: Token<Handler>, implementation: Newable<NoInfer<Handler>, []>): ServiceCollection (+4 overloads)

    Registers a singleton: one instance for the root provider and all its scopes.

    • addSingleton(Class) / addSingleton(Class, [deps]): the class is its own token.
    • addSingleton(token, Implementation, [deps]): deps are checked against the constructor's parameters.
    • addSingleton(token, (provider) => instance): a factory, may be async.

    addSingleton
    (
    const Handlers: InjectionToken<Handler>
    Handlers
    ,
    class Handler
    Handler
    )
    .
    ServiceCollection.buildServiceProvider(options?: BuildOptions): ServiceProvider

    Builds the provider. Registrations are copied, so changing this collection afterwards does not affect providers already built.

    buildServiceProvider
    ();
    const [
    const first: Handler
    first
    ,
    const second: Handler
    second
    ] = await
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getServices<Handler>(token: Token<Handler>): Promise<Handler[]>

    Resolves every registration of token, in registration order. Empty if none.

    getServices
    (
    const Handlers: InjectionToken<Handler>
    Handlers
    );
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    (
    const first: Handler
    first
    ===
    const second: Handler
    second
    ); // false: two registrations, two singletons

    Concurrent resolutions share one instance. If several resolutions of a singleton (or of a scoped service in the same scope) are in flight at once, for example in Promise.all while an async factory or onInit is still running, they all wait for the same instance. The service is built once. Transients are always distinct.

    let
    let created: number
    created
    = 0;
    const
    const provider: ServiceProvider
    provider
    = new
    new ServiceCollection(): ServiceCollection

    Collects service registrations, then builds a

    ServiceProvider

    . Modeled on .NET's IServiceCollection.

    @example

    const services = new ServiceCollection();
    services.addSingleton(Logger, ConsoleLogger);
    services.addScoped(UserService, [Logger]);
    const provider = services.buildServiceProvider({ validateScopes: true });

    ServiceCollection
    ()
    .
    ServiceCollection.addSingleton<unknown>(token: Token<unknown>, factory: ServiceFactory<unknown>): ServiceCollection (+4 overloads)

    Registers a singleton: one instance for the root provider and all its scopes.

    • addSingleton(Class) / addSingleton(Class, [deps]): the class is its own token.
    • addSingleton(token, Implementation, [deps]): deps are checked against the constructor's parameters.
    • addSingleton(token, (provider) => instance): a factory, may be async.

    addSingleton
    ('db', async () => {
    let created: number
    created
    ++;
    await new
    var Promise: PromiseConstructor
    new <unknown>(executor: (resolve: (value: unknown) => void, reject: (reason?: any) => void) => void) => Promise<unknown>

    Creates a new Promise.

    @param ― executor A callback used to initialize the promise. This callback is passed two arguments: a resolve callback used to resolve the promise with a value or the result of another promise, and a reject callback used to reject the promise with a provided reason or error.

    Promise
    ((
    r: (value: unknown) => void
    r
    ) =>
    function setTimeout(callback: (_: void) => void, delay?: number): NodeJS.Timeout (+2 overloads)
    setTimeout
    (
    r: (value: unknown) => void
    r
    , 50)); // slow connect
    return {
    query: (sql: string) => never[]
    query
    : (
    sql: string
    sql
    : string) => [] };
    })
    .
    ServiceCollection.buildServiceProvider(options?: BuildOptions): ServiceProvider

    Builds the provider. Registrations are copied, so changing this collection afterwards does not affect providers already built.

    buildServiceProvider
    ();
    await
    var Promise: PromiseConstructor

    Represents the completion of an asynchronous operation

    Promise
    .
    PromiseConstructor.all<[Promise<unknown>, Promise<unknown>, Promise<unknown>]>(values: [Promise<unknown>, Promise<unknown>, Promise<unknown>]): Promise<[unknown, unknown, unknown]> (+1 overload)

    Creates a Promise that is resolved with an array of results when all of the provided Promises resolve, or rejected when any Promise is rejected.

    @param ― values An array of Promises.

    @returns ― A new Promise.

    all
    ([
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getService<unknown>(token: Token<unknown>): Promise<unknown>

    Resolves token, or returns undefined if it is not registered. With several registrations, the last one wins.

    getService
    ('db'),
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getService<unknown>(token: Token<unknown>): Promise<unknown>

    Resolves token, or returns undefined if it is not registered. With several registrations, the last one wins.

    getService
    ('db'),
    const provider: ServiceProvider
    provider
    .
    ServiceProvider.getService<unknown>(token: Token<unknown>): Promise<unknown>

    Resolves token, or returns undefined if it is not registered. With several registrations, the last one wins.

    getService
    ('db')]);
    var console: Console

    The console module provides a simple debugging console that is similar to the JavaScript console mechanism provided by web browsers.

    The module exports two specific components:

    • A Console class with methods such as console.log(), console.error() and console.warn() that can be used to write to any Node.js stream.
    • A global console instance configured to write to process.stdout and process.stderr. The global console can be used without importing the node:console module.

    Warning: The global console object's methods are neither consistently synchronous like the browser APIs they resemble, nor are they consistently asynchronous like all other Node.js streams. See the note on process I/O for more information.

    Example using the global console:

    console.log('hello world');
    // Prints: hello world, to stdout
    console.log('hello %s', 'world');
    // Prints: hello world, to stdout
    console.error(new Error('Whoops, something bad happened'));
    // Prints error message and stack trace to stderr:
    // Error: Whoops, something bad happened
    // at [eval]:5:15
    // at Script.runInThisContext (node:vm:132:18)
    // at Object.runInThisContext (node:vm:309:38)
    // at node:internal/process/execution:77:19
    // at [eval]-wrapper:6:22
    // at evalScript (node:internal/process/execution:76:60)
    // at node:internal/main/eval_string:23:3
    const name = 'Will Robinson';
    console.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to stderr

    Example using the Console class:

    const out = getStreamSomehow();
    const err = getStreamSomehow();
    const myConsole = new console.Console(out, err);
    myConsole.log('hello world');
    // Prints: hello world, to out
    myConsole.log('hello %s', 'world');
    // Prints: hello world, to out
    myConsole.error(new Error('Whoops, something bad happened'));
    // Prints: [Error: Whoops, something bad happened], to err
    const name = 'Will Robinson';
    myConsole.warn(`Danger ${name}! Danger!`);
    // Prints: Danger Will Robinson! Danger!, to err

    @see ― source

    console
    .
    Console.log(message?: any, ...optionalParams: any[]): void (+1 overload)

    Prints to stdout with newline. Multiple arguments can be passed, with the first used as the primary message and all additional used as substitution values similar to printf(3) (the arguments are all passed to util.format()).

    const count = 5;
    console.log('count: %d', count);
    // Prints: count: 5, to stdout
    console.log('count:', count);
    // Prints: count: 5, to stdout

    See util.format() for more information.

    @since ― v0.1.100

    log
    (
    let created: number
    created
    ); // 1