nano-injector
    Preparing search index...

    Class Injector

    The central entity of the library. It holds provider bindings and resolves dependencies.

    Index

    Constructors

    • Parameters

      • params: { logger?: (msg: string) => unknown; name?: string; parent?: Injector } = {}
        • Optionallogger?: (msg: string) => unknown

          Custom logger function.

        • Optionalname?: string

          Name of the injector (useful for debugging).

        • Optionalparent?: Injector

          Parent injector for composing injectors.

      Returns Injector

    Methods

    • Creates a new binder and links it to the specified providers. If a provider is already bound, the binding is overridden.

      Type Parameters

      • ProviderT extends Provider<unknown>[]
      • ValueT extends unknown

      Parameters

      • ...providers: ProviderT

        The providers to bind.

      Returns Binder<ValueT>

    • Activates the injector and calls the given function with the provided arguments.

      Type Parameters

      • FuncT extends (...args: any[]) => unknown

      Parameters

      • func: FuncT

        function which should be called

      • ...args: Parameters<FuncT>

        args which should be passed to the called function

      Returns ReturnType<FuncT>

    • Activates the injector and creates a new instance of the given class using the provided arguments.

      Type Parameters

      • ClassT extends new (...args: any[]) => unknown

      Parameters

      Returns InstanceType<ClassT>

    • Resolves specific providers to their values and assigns them to the instance's properties.

      Type Parameters

      • T extends object
      • K extends string | number | symbol

      Parameters

      Returns void