Interface Container

Container API.

interface Container {
    get registry(): Registry;
    clearCache(): void;
    createChild(): Container;
    getCached<Value>(token: Token<Value>): undefined | Value;
    isRegistered(token: Type<any> | Constructor<any>): boolean;
    register<Instance extends object>(Class: Constructor<Instance>): this;
    register<Instance extends object>(
        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 extends object>(Class: Constructor<Instance>): Instance;
    resolve<Value>(token: Token<Value>): Value;
    resolve<Values extends unknown[]>(
        ...tokens: TokenList<Values>,
    ): Values[number];
    resolveAll<Instance extends object>(
        Class: Constructor<Instance>,
    ): Instance[];
    resolveAll<Value>(token: Token<Value>): NonNullable<Value>[];
    resolveAll<Values extends unknown[]>(
        ...tokens: TokenList<Values>,
    ): NonNullable<Values[number]>[];
    unregister(token: Type<any> | Constructor<any>): 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

  • 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]>[]