TSinjex

The main class for the Dependency Injection Container TSinjex.

  • Register for registering a class in the DI container.
  • RegisterInstance for registering an instance in the DI container.
  • Inject for injecting a dependency into a property.

  • register for registering a dependency (class or instance) as a function.
  • resolve for resolving a dependency as a function.

Implements

Constructors

Properties

_dependencies: Map<string, IDependency> = ...

The dependencies map.

_instance: TSinjex

The singleton instance of the TSinjex class.

Methods

  • Register a dependency.

    Type Parameters

    • T

    Parameters

    • identifier: string

      The identifier of the dependency.

    • dependency: T

      The dependency to register.

    • deprecated: boolean = false

      If true, the dependency is deprecated => a warning is logged when the dependency is resolved.

    Returns void

  • Resolve a dependency

    Type Parameters

    • T

    Parameters

    • identifier: string

      The identifier of the dependency

    • necessary: boolean = true

      If true, throws an error if the dependency is not found

    Returns undefined | T

    The resolved dependency or undefined if the dependency is not found

    A DependencyResolutionError if the dependency is not found and necessary.