Function Injectable

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

    Ex:

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

    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.

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

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

    Note: the list of dependencies must contain only string literals or string consts.

    Ex:

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

    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 Injectable 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.

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

Generated using TypeDoc