Class ProxyDiContainer

A dependency injection container

Implements

  • IProxyDiContainer

Constructors

  • Creates a new instance of ProxyDiContainer.

    Parameters

    • Optionalsettings: ContainerSettings

      Optional container settings to override defaults.

    • Optionalparent: ProxyDiContainer

      Optional parent container.

    Returns ProxyDiContainer

Properties

id: number

Just unique number identifier for this container, nothing more

Optional parent container from which this container can inherit dependencies.

settings: Required<ContainerSettings>

Settings that control the behavior of the container and it's children

Accessors

Methods

  • Registers a dependency in the container. Could register eacher class or instance. In case of class, it will be instantiated without any parameters.

    Type Parameters

    • T

    Parameters

    • DependencyClass: DependencyClass<T>
    • OptionaldependencyId: DependencyId | DependencyClass<any>

      The unique identifier for the dependency in this container. Can be a string, symbol, or class constructor (which will be normalized to class name).

    Returns T & Dependency & {
        "[DEPENDENCY_ID]": DependencyId;
        "[PROXYDI_CONTAINER]": IProxyDiContainer;
    }

    Dependency instance, registered in container

    • [DEPENDENCY_ID]: DependencyId

      Unique identifier that could use to resolve this instance from container where it was registered

    • [PROXYDI_CONTAINER]: IProxyDiContainer

      ProxyDi container in which this instance was registered

    Error if dependency is already registered and rewriting is not allowed or if invalid dependency (not object) is provided and this it now allowed.

  • Registers a dependency in the container. Could register eacher class or instance. In case of class, it will be instantiated without any parameters.

    Type Parameters

    • T

    Parameters

    • dependency: T extends {} ? never : T

      The dependency instance or dependency class.

    • OptionaldependencyId: DependencyId | DependencyClass<any>

      The unique identifier for the dependency in this container. Can be a string, symbol, or class constructor (which will be normalized to class name).

    Returns T & Dependency & {
        "[DEPENDENCY_ID]": DependencyId;
        "[PROXYDI_CONTAINER]": IProxyDiContainer;
    }

    Dependency instance, registered in container

    • [DEPENDENCY_ID]: DependencyId

      Unique identifier that could use to resolve this instance from container where it was registered

    • [PROXYDI_CONTAINER]: IProxyDiContainer

      ProxyDi container in which this instance was registered

    Error if dependency is already registered and rewriting is not allowed or if invalid dependency (not object) is provided and this it now allowed.

  • Checks if a dependency with the given ID is known to the container based on the scope.

    Parameters

    • dependencyId: DependencyId | DependencyClass<any>

      The identifier of the dependency. Can be a string, symbol, or class constructor (which will be normalized to class name).

    • scope: ResolveScope = ...

      Bitwise enum to control where to search. Defaults to Current | Parent (searches up the hierarchy).

    Returns boolean

    True if the dependency is known, false otherwise.

  • Checks if a dependency with the given ID exists in this container only (does not check parents)

    Parameters

    • dependencyId: DependencyId | DependencyClass<any>

      The identifier of the dependency. Can be a string, symbol, or class constructor (which will be normalized to class name).

    Returns boolean

    True if the dependency exists in this container, false otherwise.

  • Resolves a dependency either by its dependency ID or through a class constructor for auto-injectable classes.

    Type Parameters

    • T

    Parameters

    • dependencyId: DependencyId
    • Optionalscope: ResolveScope

      Bitwise enum to control where to search. Defaults to Current | Parent (searches up the hierarchy).

    Returns T & Dependency & {
        "[DEPENDENCY_ID]": DependencyId;
        "[PROXYDI_CONTAINER]": IProxyDiContainer;
    }

    The resolved dependency instance with container metadata.

    • [DEPENDENCY_ID]: DependencyId

      Unique identifier that could use to resolve this instance from container where it was registered

    • [PROXYDI_CONTAINER]: IProxyDiContainer

      ProxyDi container in which this instance was registered

    Error if the dependency cannot be found or is not auto injectable.

  • Resolves a dependency either by its dependency ID or through a class constructor for auto-injectable classes.

    Type Parameters

    • T extends DependencyClass<any>

    Parameters

    • SomeClass: T
    • Optionalscope: ResolveScope

      Bitwise enum to control where to search. Defaults to Current | Parent (searches up the hierarchy).

    Returns InstanceType<T> & Dependency & {
        "[DEPENDENCY_ID]": DependencyId;
        "[PROXYDI_CONTAINER]": IProxyDiContainer;
    }

    The resolved dependency instance with container metadata.

    • [DEPENDENCY_ID]: DependencyId

      Unique identifier that could use to resolve this instance from container where it was registered

    • [PROXYDI_CONTAINER]: IProxyDiContainer

      ProxyDi container in which this instance was registered

    Error if the dependency cannot be found or is not auto injectable.

  • Injects dependencies to the given object based on its defined injections metadata. Does not affect the container.

    Parameters

    • injectionsOwner: any

      The object to inject dependencies into.

    Returns void

  • Creates instances for all injectable classes and registers them in this container.

    Returns ProxyDiContainer

    This container to allow use along with constructor.

  • Finalizes dependency injections, prevents further rewriting of dependencies, and recursively bakes injections for child containers.

    Returns void

  • Creates a child container that inherits settings and dependencies from this container.

    Returns ProxyDiContainer

    A new child instance of ProxyDiContainer.

  • Removes a given dependency from the container using either the dependency instance or its ID.

    Parameters

    Returns void

  • Destroys the container by removing all dependencies, recursively destroying child containers and removing itself from its parent.

    Returns void