Function Target

  • Class decorator factory. Links the Targeted constructor to its corresponding instance by applying the supplied factoryArgs. Employ this helper to link Targeted constructors with required arguments. Supplying a target constructor overrides its linked instance, if any, with the constructed instance.

    Type Parameters

    • K extends (new (...args) => any)

      The Targeted constructor type.

    Parameters

    • Optional factoryArgs: ConstructorParameters<K>

      The arguments for the Targeted constructor.

    • Optional target: K

      An optional Target constructor to override.

    Returns ((constructor) => void)

    A class constructor decorator.

      • (constructor): void
      • Parameters

        • constructor: K

        Returns void

    Example

    Target a service:

    import { Target } from '@sgrud/core';

    ⁠@Target(['default'])
    export class Service {

    public constructor(
    public readonly param: string
    ) {}

    }

    Example

    Factor a Targeted service:

    import { Factor, type Target } from '@sgrud/core';
    import { Service } from './service';

    export class ServiceHandler {

    ⁠@Factor<Target<Service>>(() => Service)
    public readonly service!: Service;

    }

    See

Generated using TypeDoc