@kayahr/cdi

    Class Context

    Dependency injection context.

    Index

    Methods

    • Activates this dependency injection context so all code which retrieves the context via () work with this context.

      Returns Context

      The previously active context.

    • Creates a new child dependency injection context. The context is not activated, you have to do this yourself with () if needed.

      Returns Context

      The created child dependency injection context.

    • Returns the context containing the dependency matching the given qualifier. Starts searching with this context and then bubbles up to the parent context if not found in this one.

      Parameters

      Returns null | Context

      The context containing the dependency matching the given qualifier. Null if not found anywhere.

    • Type Parameters

      • T
      • P extends unknown[]

      Parameters

      • fn: (...params: P) => T

      Returns Promise<(...params: unknown[]) => T> | ((...params: unknown[]) => T)

    • Type Parameters

      • T

      Parameters

      Returns T | Promise<T>

    • Type Parameters

      • T
      • P extends unknown[]

      Parameters

      • fn: (...params: P) => T

      Returns Promise<(...params: unknown[]) => T>

    • Type Parameters

      • T

      Parameters

      Returns Promise<T>

    • Type Parameters

      • T
      • P extends unknown[]

      Parameters

      • fn: (...params: P) => T

      Returns (...params: unknown[]) => T

    • Type Parameters

      • T

      Parameters

      Returns T

    • Checks if this context (or its parents) have an injectable matching the given qualifier.

      Parameters

      • qualifier: Qualifier

        The dependency injection qualifier to look for.

      Returns boolean

      True if context or its parents have a matching injectable, false if not.

    • Checks if this dependency injection context is currently active.

      Returns boolean

      True if this dependency injection context is active, false if not.

    • Removes the injectable with the given qualifier from this dependency injection context. It is only removed from this context, the removal does not bubble up the parent hierarchy.

      Parameters

      • qualifier: Qualifier

        The qualifier to remove.

      Returns boolean

      True if an injectable was found and removed, false if not.

    • Type Parameters

      • T

      Parameters

      Returns this

    • Type Parameters

      • T
      • P extends unknown[]

      Parameters

      • type: Class<T>
      • factory: Factory<T, P>
      • options: InjectableOptions<
            NoInfer<{ [K in string | number | symbol]: Qualifier<P[K<K>]> }>,
        > & {
            inject: NoInfer<{ [K in string | number | symbol]: Qualifier<P[K<K>]> }>;
        }

      Returns this

    • Type Parameters

      • T
      • P extends unknown[]

      Parameters

      Returns this

    • Registers the given injectable function in this dependency injection context. Using null in the inject array defines placeholders for pass-through function parameter. So when injecting a function with inject arguments [ null, Service, null ] the resolved function expects two parameters which are filled into the placeholders while Service is injected automatically.

      Type Parameters

      • P extends unknown[]

      Parameters

      • func: (...params: P) => unknown

        The value to inject.

      • inject: NoInfer<{ [K in string | number | symbol]: NullableQualifier<P[K<K>]> }>

        The parameter types. Must match the function signature but allows specifying null as type for marking pass-through parameters.

      • Optionalname: string | symbol | (string | symbol)[]

        Optional name (or names) under which to inject the function. If not set then function is only injected via its type.

      Returns this

    • Registers the given injectable value in this dependency injection context.

      Type Parameters

      • T extends Object

      Parameters

      • value: T

        The value to inject.

      • Optionalname: string | symbol | (string | symbol)[]

        Optional name (or names) under which to inject the value. If not set then value is only injected via its type.

      Returns this

    MMNEPVFCICPMFPCPTTAAATR