UNPKG

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