UNPKG

1.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.mixin = exports.Injectable = void 0;
4const uuid_1 = require("uuid");
5const constants_1 = require("../../constants");
6/**
7 * Decorator that marks a class as a [provider](https://docs.nestjs.com/providers).
8 * Providers can be injected into other classes via constructor parameter injection
9 * using Nest's built-in [Dependency Injection (DI)](https://docs.nestjs.com/providers#dependency-injection)
10 * system.
11 *
12 * When injecting a provider, it must be visible within the module scope (loosely
13 * speaking, the containing module) of the class it is being injected into. This
14 * can be done by:
15 *
16 * - defining the provider in the same module scope
17 * - exporting the provider from one module scope and importing that module into the
18 * module scope of the class being injected into
19 * - exporting the provider from a module that is marked as global using the
20 * `@Global()` decorator
21 *
22 * Providers can also be defined in a more explicit and imperative form using
23 * various [custom provider](https://docs.nestjs.com/fundamentals/custom-providers) techniques that expose
24 * more capabilities of the DI system.
25 *
26 * @param options options specifying scope of injectable
27 *
28 * @see [Providers](https://docs.nestjs.com/providers)
29 * @see [Custom Providers](https://docs.nestjs.com/fundamentals/custom-providers)
30 * @see [Injection Scopes](https://docs.nestjs.com/fundamentals/injection-scopes)
31 *
32 * @publicApi
33 */
34function Injectable(options) {
35 return (target) => {
36 Reflect.defineMetadata(constants_1.INJECTABLE_WATERMARK, true, target);
37 Reflect.defineMetadata(constants_1.SCOPE_OPTIONS_METADATA, options, target);
38 };
39}
40exports.Injectable = Injectable;
41function mixin(mixinClass) {
42 Object.defineProperty(mixinClass, 'name', {
43 value: (0, uuid_1.v4)(),
44 });
45 Injectable()(mixinClass);
46 return mixinClass;
47}
48exports.mixin = mixin;