# All files / common/decorators/modules single-scope.decorator.ts

88.89% Statements 8/9
100% Branches 0/0
66.67% Functions 2/3
88.89% Lines 8/9

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    191x

    1x
    2x
    2x
    2x

    2x
    2x
    2x

     import { SHARED_MODULE_METADATA } from '../../constants';
    /**
     * Makes the module single-scoped (not singleton).
     * In this case, Nest will always create a new instance of this particular module when it's imported by another one.
     */
    export function SingleScope(): ClassDecorator {
      return (target: any) => {
        const Metatype = target as FunctionConstructor;
        const Type = class extends Metatype {
          constructor(...args) {
            super(...args);
          }
        };
        Reflect.defineMetadata(SHARED_MODULE_METADATA, true, Type);
        Object.defineProperty(Type, 'name', { value: target.name });
        return Type as any;
      };
    }