@lppedd/di-wise-neo - v0.6.0
    Preparing search index...

    Interface Container

    Container API.

    interface Container {
        isDisposed: boolean;
        options: ContainerOptions;
        parent: undefined | Container;
        clearCache(): unknown[];
        createChild(options?: Partial<ContainerOptions>): Container;
        dispose(): void;
        getAllCached<Value>(token: Token<Value>): Value[];
        getCached<Value>(token: Token<Value>): undefined | Value;
        isRegistered(token: Type<any> | Constructor<any>): boolean;
        register<Instance extends object>(Class: Constructor<Instance>): Container;
        register<Instance extends object, ProviderInstance extends object>(
            token: Token<Instance>,
            provider: ClassProvider<ProviderInstance>,
            options?: RegistrationOptions,
        ): Container;
        register<Value, ProviderValue>(
            token: Token<Value>,
            provider: FactoryProvider<ProviderValue>,
            options?: RegistrationOptions,
        ): Container;
        register<Value, ProviderValue>(
            token: Token<Value>,
            provider: ExistingProvider<ProviderValue>,
        ): Container;
        register<Value, ProviderValue>(
            token: Token<Value>,
            provider: ValueProvider<ProviderValue>,
        ): Container;
        registerAlias<Value, ProvidedValue>(
            targetToken: Token<ProvidedValue>,
            aliasTokens: Tokens<Value>,
        ): void;
        registerClass<Instance extends object>(Class: Constructor<Instance>): void;
        registerClass<Instance extends object, ProvidedInstance extends object>(
            token: Token<Instance>,
            Class: Constructor<ProvidedInstance>,
            options?: RegistrationOptions,
        ): void;
        registerFactory<Value, ProvidedValue>(
            token: Token<Value>,
            factory: (...args: []) => ProvidedValue,
            options?: RegistrationOptions,
        ): void;
        registerValue<Value, ProvidedValue>(
            token: Token<Value>,
            value: ProvidedValue,
        ): void;
        resetRegistry(): unknown[];
        resolve<Instance extends object>(
            Class: Constructor<Instance>,
            optional?: false,
        ): Instance;
        resolve<Instance extends object>(
            Class: Constructor<Instance>,
            optional: true,
        ): undefined | Instance;
        resolve<Instance extends object>(
            Class: Constructor<Instance>,
            optional?: boolean,
        ): undefined | Instance;
        resolve<Value>(token: Token<Value>, optional?: false): Value;
        resolve<Value>(token: Token<Value>, optional: true): undefined | Value;
        resolve<Value>(token: Token<Value>, optional?: boolean): undefined | Value;
        resolveAll<Instance extends object>(
            Class: Constructor<Instance>,
            optional?: false,
        ): Instance[];
        resolveAll<Instance extends object>(
            Class: Constructor<Instance>,
            optional: true,
        ): Instance[];
        resolveAll<Instance extends object>(
            Class: Constructor<Instance>,
            optional?: boolean,
        ): Instance[];
        resolveAll<Value>(
            token: Token<Value>,
            optional?: false,
        ): NonNullable<Value>[];
        resolveAll<Value>(
            token: Token<Value>,
            optional: true,
        ): NonNullable<Value>[];
        resolveAll<Value>(
            token: Token<Value>,
            optional?: boolean,
        ): NonNullable<Value>[];
        unregister<Value>(token: Token<Value>): Value[];
    }
    Index

    Properties

    isDisposed: boolean

    Whether this container is disposed.

    The options used to create this container.

    parent: undefined | Container

    The parent container, or undefined if this is the root container.

    Methods

    • Clears and returns all distinct cached values from this container's internal registry. Values from ValueProvider registrations are not included, as they are never cached.

      Note that only this container is affected. Parent containers, if any, remain unchanged.

      Returns unknown[]

    • Disposes this container and all its cached values.

      Token values implementing a Disposable interface (e.g., objects with a dispose() function) are automatically disposed during this process.

      Note that children containers are disposed first, in creation order.

      Returns void

    • Returns all cached values associated with registrations of the token, in the order they were registered, or an empty array if none have been cached.

      If the token has at least one registration in the current container, cached values are taken from those registrations. Otherwise, cached values may be retrieved from parent containers, if any.

      Values are never cached for tokens with transient or resolution scope, or for ValueProvider registrations.

      Type Parameters

      • Value

      Parameters

      Returns Value[]

    • Returns the cached value from the most recent registration of the token, or undefined if no value has been cached yet (the token has not been resolved yet).

      If the token has at least one registration in this container, the cached value is taken from the most recent of those registrations. Otherwise, it may be retrieved from parent containers, if any.

      Values are never cached for tokens with transient or resolution scope, or for ValueProvider registrations.

      Type Parameters

      • Value

      Parameters

      Returns undefined | Value

    • Returns whether the token is registered in this container or in parent containers, if any.

      Parameters

      Returns boolean

    • Removes all registrations from this container's internal registry.

      Returns an array of distinct cached values that were stored within the removed registrations. Values from ValueProvider registrations are not included, as they are not cached.

      Note that only this container is affected. Parent containers, if any, remain unchanged.

      Returns unknown[]

    • Resolves the given class to the instance associated with it.

      If the class is registered in this container or any of its parent containers, an instance is created using the most recent registration.

      If the class is not registered, but it is decorated with AutoRegister, or ContainerOptions.autoRegister is true, the class is registered automatically. Otherwise, resolution fails. The scope for the automatic registration is determined by either the Scoped decorator on the class, or ContainerOptions.defaultScope.

      If optional is false or is not passed and the class is not registered in the container (and could not be auto-registered), an error is thrown. Otherwise, if optional is true, undefined is returned.

      The resolution behavior depends on the Provider used during registration:

      • For ValueProvider, the explicitly provided instance is returned.
      • For FactoryProvider, the factory function is invoked to create the instance.
      • For ClassProvider, a new instance of the class is created according to its scope.
      • For ExistingProvider, the instance is resolved by referring to another registered token.

      If the class is registered with container scope, the resolved instance is cached in the container's internal registry.

      Type Parameters

      • Instance extends object

      Parameters

      Returns Instance

    • Type Parameters

      • Instance extends object

      Parameters

      Returns undefined | Instance

    • Type Parameters

      • Instance extends object

      Parameters

      Returns undefined | Instance

    • Resolves the given token to the value associated with it.

      If the token is registered in this container or any of its parent containers, its value is resolved using the most recent registration.

      If optional is false or not passed and the token is not registered in the container, an error is thrown. Otherwise, if optional is true, undefined is returned.

      The resolution behavior depends on the Provider used during registration:

      • For ValueProvider, the explicitly provided value is returned.
      • For FactoryProvider, the factory function is invoked to create the value.
      • For ClassProvider, a new instance of the class is created according to its scope.
      • For ExistingProvider, the value is resolved by referring to another registered token.

      If the token is registered with container scope, the resolved value is cached in the container's internal registry.

      Type Parameters

      • Value

      Parameters

      Returns Value

    • Type Parameters

      • Value

      Parameters

      Returns undefined | Value

    • Type Parameters

      • Value

      Parameters

      Returns undefined | Value

    • Resolves the given class to all instances provided by the registrations associated with it.

      If the class is not registered, but it is decorated with AutoRegister, or ContainerOptions.autoRegister is true, the class is registered automatically. Otherwise, resolution fails. The scope for the automatic registration is determined by either the Scoped decorator on the class, or ContainerOptions.defaultScope.

      If optional is false or is not passed and the class is not registered in the container (and could not be auto-registered), an error is thrown. Otherwise, if optional is true, an empty array is returned.

      The resolution behavior depends on the Provider used during registration:

      • For ValueProvider, the explicitly provided instance is returned.
      • For FactoryProvider, the factory function is invoked to create the instance.
      • For ClassProvider, a new instance of the class is created according to its scope.
      • For ExistingProvider, the instance is resolved by referring to another registered token.

      If the class is registered with container scope, the resolved instances are cached in the container's internal registry.

      A separate instance of the class is created for each provider.

      Type Parameters

      • Instance extends object

      Parameters

      Returns Instance[]

      The documentation for resolve(Class: Constructor)

    • Type Parameters

      • Instance extends object

      Parameters

      Returns Instance[]

    • Type Parameters

      • Instance extends object

      Parameters

      Returns Instance[]

    • Resolves the given token to all values provided by the registrations associated with it.

      If optional is false or not passed and the token is not registered in the container, an error is thrown. Otherwise, if optional is true, an empty array is returned.

      The resolution behavior depends on the Provider used during registration:

      • For ValueProvider, the explicitly provided value is returned.
      • For FactoryProvider, the factory function is invoked to create the value.
      • For ClassProvider, a new instance of the class is created according to its scope.
      • For ExistingProvider, the value is resolved by referring to another registered token.

      If the token is registered with container scope, the resolved values are cached in the container's internal registry.

      Type Parameters

      • Value

      Parameters

      Returns NonNullable<Value>[]

      The documentation for resolve(token: Token)

    • Type Parameters

      • Value

      Parameters

      Returns NonNullable<Value>[]

    • Type Parameters

      • Value

      Parameters

      Returns NonNullable<Value>[]

    • Removes all registrations for the given token from the container's internal registry.

      Returns an array of distinct cached values that were stored within the removed registrations. Values from ValueProvider registrations are not included, as they are not cached.

      Note that only this container is affected. Parent containers, if any, remain unchanged.

      Type Parameters

      • Value

      Parameters

      Returns Value[]