• A decorator to inject a dependency from a DI (Dependency Injection) container. The dependency is lazily evaluated when the property is accessed for the first time. This can help avoid issues like circular dependencies and not-found dependencies.

    Type Parameters

    • T
    • U

    Parameters

    • identifier: string

      The identifier used to resolve the dependency from the DI container.

    • Optionalinit: InitDelegate<T, U>

      An optional initializer function to transform the dependency before injection.

    • necessary: boolean = true

      Indicates if the dependency is necessary.

      • If true, an error will be thrown if the dependency cannot be resolved.
      • If false, undefined will be returned if the dependency cannot be resolved.

    Returns ((target: unknown, propertyKey: string | symbol) => void)

    A decorator function to be applied on the class property.

      • (target, propertyKey): void
      • Parameters

        • target: unknown
        • propertyKey: string | symbol

        Returns void

    TSinjex

    class MyClass {
    \@Inject<MyDependency>('MyDependencyIdentifier')
    private myDependency!: MyDependency;
    }
    class MyClass {
    \@Inject('ILogger_', (x: ILogger_) => x.getLogger('Tags'), false)
    private _logger?: ILogger;
    }