Function Injectable

  • Create an Injectable function with no dependencies (i.e. arguments).

    Ex:

    const createMyService = Factory(
    'MyService',
    () => { ... },
    )

    Type Parameters

    • Token extends string

    • Service

    Parameters

    • token: Token

      A unique string Token which will correspond to the created Service.

    • fn: (() => Service)

      A function with no arguments which returns the Service.

        • (): Service
        • Returns Service

    Returns InjectableFunction<any, [], Token, Service>

  • Create an Injectable function with dependencies (i.e. arguments).

    Note: the list of dependencies must be readonly – that is, a literal tuple marked as const. This tuple must contain only string literals or string consts.

    Ex:

    const DependencyB = 'DependencyB'
    const createMyService = Factory(
    'MyService',
    ['DependencyA', DependencyB] as const,
    (a: A, b: B) => { ... },
    )

    Type Parameters

    • Token extends string

    • Tokens extends readonly string[]

    • Params extends readonly any[]

    • Service

    Parameters

    • token: Token

      A unique string Token which will correspond to the created Service.

    • dependencies: Tokens

      A readonly list of Tokens corresponding to dependencies (i.e. arguments to the Factory), which will be resolved by the Container to which this Factory is provided.

    • fn: ((...args) => Service)

      A function with arguments matching in type and length to the given list of dependencies. When called, it must return the Service.

        • (...args): Service
        • Parameters

          • Rest ...args: Tokens["length"] extends Params["length"]
                ? Params
                : void[]

          Returns Service

    Returns Tokens["length"] extends Params["length"]
        ? InjectableFunction<ServicesFromTokenizedParams<Tokens, Params>, Tokens, Token, Service>
        : never

Generated using TypeDoc