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

      The unique identifier for the dependency in this container.

    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.

    • dependencyId: DependencyId

      The unique identifier for the dependency in this container.

    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 or its ancestors which means that it can be resolved by this container

    Parameters

    • dependencyId: DependencyId

      The identifier of the dependency.

    Returns boolean

    True if the dependency is known, 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

    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

    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

    • dependencyOrId: DependencyId | ContainerizedDependency

      The dependency instance or dependency identifier to remove.

    Returns void

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

    Returns void