Interface Container

Container API.

interface Container {
    get registry(): Registry;
    clearCache(): void;
    createChild(): Container;
    getCached<Value>(token: Token<Value>): undefined | Value;
    isRegistered<Value>(token: Token<Value>): boolean;
    register<Instance>(Class: Constructor<Instance>): this;
    register<Instance>(token: Token<Instance>, provider: ClassProvider<Instance>, options?: RegistrationOptions): this;
    register<Value>(token: Token<Value>, provider: FactoryProvider<Value>, options?: RegistrationOptions): this;
    register<Value>(token: Token<Value>, provider: ValueProvider<Value>): this;
    resetRegistry(): void;
    resolve<Instance>(Class: Constructor<Instance>): Instance;
    resolve<Value>(token: Token<Value>): Value;
    resolve<Values>(...tokens: TokenList<Values>): Values[number];
    resolveAll<Instance>(Class: Constructor<Instance>): Instance[];
    resolveAll<Value>(token: Token<Value>): NonNullable<Value>[];
    resolveAll<Values>(...tokens: TokenList<Values>): NonNullable<Values[number]>[];
    unregister<Value>(token: Token<Value>): this;
}

Accessors

  • get registry(): Registry
  • The underlying registry.

    Returns Registry

Methods

  • Clear the cached instances with container scope.

    The registered constants with ValueProvider are not affected.

    Returns void

  • Check if a token is registered in the container or its ancestors.

    Type Parameters

    • Value

    Parameters

    Returns boolean

  • Remove all registrations from the internal registry.

    Returns void

  • Resolve a class token to instances with all registered providers.

    Type Parameters

    • Instance extends object

    Parameters

    Returns Instance[]

  • Resolve a token to instances with all registered providers.

    The returned array will not contain null or undefined values.

    Type Parameters

    • Value

    Parameters

    Returns NonNullable<Value>[]

  • Resolve a token to instances with all registered providers, by checking each token in order until a registered one is found.

    The returned array will not contain null or undefined values.

    Type Parameters

    • Values extends unknown[]

    Parameters

    Returns NonNullable<Values[number]>[]

  • Remove a registration from the internal registry.

    Type Parameters

    • Value

    Parameters

    Returns this