Function Service

  • Marks class as a service that can be injected using Container. Uses the default options, wherein the class can be passed to .get and an instance of it will be returned. By default, the service shall be registered upon the defaultContainer container.

    Parameters

    • dependencies: AnyServiceDependency[]

      The dependencies to provide upon initialisation of this service. These will be provided to the service as arguments to its constructor. They must be valid identifiers in the container the service shall be executed under.

    Returns ClassDecorator

    A decorator which is then used upon a class.

    Remarks

    This is a TypeScript decorator.

    Example

    Here is an example:

    @Service([ ])
    class OtherService { }

    @Service([OtherService])
    class MyService {
    constructor (private otherService: OtherService) { }
    }
  • Marks class as a service that can be injected using Container. The options allow customization of how the service is injected. By default, the service shall be registered upon the defaultContainer container.

    Type Parameters

    • T = unknown

    Parameters

    • options: Omit<ServiceOptions<T>, "dependencies">

      The options to use for initialisation of the service. Documentation for the options can be found in ServiceOptions.

    • dependencies: AnyServiceDependency[]

      The dependencies to provide upon initialisation of this service. These will be provided to the service as arguments to its constructor. They must be valid identifiers in the container the service shall be executed under.

    Returns ClassDecorator

    A decorator which is then used upon a class.

    Remarks

    This is a TypeScript decorator.

    Example

    Here is an example:

    const OTHER_SERVICE = new Token<OtherService>();

    @Service({ id: OTHER_SERVICE }, [ ])
    class OtherService { }

    @Service([OTHER_SERVICE])
    class MyService {
    constructor (private otherService: OtherService) { }
    }

    See

    ServiceOptions

  • Marks class as a service that can be injected using Container. The options allow customization of how the service is injected. By default, the service shall be registered upon the defaultContainer container.

    Parameters

    • options: ServiceOptionsWithDependencies<Constructable<unknown>>

      The options to use for initialisation of the service. Documentation for the options can be found in ServiceOptions. The options must also contain the dependencies that the service requires.

      If found, the specified dependencies to provide upon initialisation of this service. These will be provided to the service as arguments to its constructor. They must be valid identifiers in the container the service shall be executed under.

    Returns ClassDecorator

    A decorator which is then used upon a class.

    Remarks

    This is a TypeScript decorator.

    Example

    Here is an example:

    const OTHER_SERVICE = new Token<OtherService>();

    @Service({ id: OTHER_SERVICE, dependencies: [ ] })
    class OtherService { }

    @Service({ dependencies: [OtherService] })
    class MyService {
    constructor (private otherService: OtherService) { }
    }

Generated using TypeDoc