@lppedd/di-wise-neo - v0.11.1
    Preparing search index...

    Interface Injector

    Injector API.

    interface Injector {
        inject<Instance extends object>(
            Class: Constructor<Instance>,
            name?: string,
        ): Instance;
        inject<Value>(token: Token<Value>, name?: string): Value;
        injectAll<Instance extends object>(
            Class: Constructor<Instance>,
        ): Instance[];
        injectAll<Value>(token: Token<Value>): NonNullable<Value>[];
        optional<Instance extends object>(
            Class: Constructor<Instance>,
            name?: string,
        ): undefined | Instance;
        optional<Value>(token: Token<Value>, name?: string): undefined | Value;
        optionalAll<Instance extends object>(
            Class: Constructor<Instance>,
        ): Instance[];
        optionalAll<Value>(token: Token<Value>): NonNullable<Value>[];
        runInContext<ReturnType>(fn: () => ReturnType): ReturnType;
    }
    Index

    Methods

    • Injects the instance associated with the given class.

      Throws an error if the class is not registered in the container.

      Type Parameters

      • Instance extends object

      Parameters

      Returns Instance

    • Injects the value associated with the given token.

      Throws an error if the token is not registered in the container.

      Type Parameters

      • Value

      Parameters

      Returns Value

    • Injects all instances provided by the registrations associated with the given class.

      Throws an error if the class is not registered in the container.

      Type Parameters

      • Instance extends object

      Parameters

      Returns Instance[]

    • Injects all values provided by the registrations associated with the given token.

      Throws an error if the token is not registered in the container.

      Type Parameters

      • Value

      Parameters

      Returns NonNullable<Value>[]

    • Injects the instance associated with the given class, or undefined if the class is not registered in the container.

      Type Parameters

      • Instance extends object

      Parameters

      Returns undefined | Instance

    • Injects the value associated with the given token, or undefined if the token is not registered in the container.

      Type Parameters

      • Value

      Parameters

      Returns undefined | Value

    • Injects all instances provided by the registrations associated with the given class, or an empty array if the class is not registered in the container.

      Type Parameters

      • Instance extends object

      Parameters

      Returns Instance[]

    • Injects all values provided by the registrations associated with the given token, or an empty array if the token is not registered in the container.

      Type Parameters

      • Value

      Parameters

      Returns NonNullable<Value>[]

    • Runs a function inside the injection context of this injector.

      Note that injection functions (inject, injectAll, optional, optionalAll) are only usable synchronously: they cannot be called from asynchronous callbacks or after any await points.

      Type Parameters

      • ReturnType

      Parameters

      • fn: () => ReturnType

        The function to be run in the context of this injector.

      Returns ReturnType

      The return value of the function, if any.