# All files / container/decorators Service.ts

17.65% Statements 3/17
0% Branches 0/10
0% Functions 0/2
17.65% Lines 3/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    1x

    1x

    1x

     import { ServiceMetadata } from "../types/ServiceMetadata";
    import { Container } from "../Container";
    import { ServiceOptions } from "../types/ServiceOptions";
    import { Token } from "../Token";
    import { ControllerMappingSettings, ControllerContainerService } from "../../services/controller-service/controller.service";

    /**
     * Marks class as a service that can be injected using Container.
     */
    export function Service(): Function;

    /**
     * Marks class as a service that can be injected using Container.
     */
    export function Service(name: string): Function;

    /**
     * Marks class as a service that can be injected using Container.
     */
    export function Service(token: Token<any>): Function;

    /**
     * Marks class as a service that can be injected using Container.
     */
    export function Service<T, K extends keyof T>(options?: ServiceOptions<T, K>): Function;

    /**
     * Marks class as a service that can be injected using container.
     */
    export function Service<T, K extends keyof T>(optionsOrServiceName?: ServiceOptions<T, K> | Token<any> | string): Function {
        return function (target: Function) {

            const service: ServiceMetadata<T, K> = {
                type: target
            };

            if (typeof optionsOrServiceName === "string" || optionsOrServiceName instanceof Token) {
                service.id = optionsOrServiceName;
                service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
                service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
                service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;

            } else if (optionsOrServiceName) { // ServiceOptions
                service.id = (optionsOrServiceName as ServiceOptions<T, K>).id;
                service.factory = (optionsOrServiceName as ServiceOptions<T, K>).factory;
                service.multiple = (optionsOrServiceName as ServiceOptions<T, K>).multiple;
                service.global = (optionsOrServiceName as ServiceOptions<T, K>).global || false;
                service.transient = (optionsOrServiceName as ServiceOptions<T, K>).transient;
            }

            Container.set(service);
        };
    }