1 | import { Abstract } from '../abstract.interface';
|
2 | import { Scope } from '../scope-options.interface';
|
3 | import { Type } from '../type.interface';
|
4 | /**
|
5 | *
|
6 | * @publicApi
|
7 | */
|
8 | export declare type Provider<T = any> = Type<any> | ClassProvider<T> | ValueProvider<T> | FactoryProvider<T> | ExistingProvider<T>;
|
9 | /**
|
10 | * Interface defining a *Class* type provider.
|
11 | *
|
12 | * For example:
|
13 | * ```typescript
|
14 | * const configServiceProvider = {
|
15 | * provide: ConfigService,
|
16 | * useClass:
|
17 | * process.env.NODE_ENV === 'development'
|
18 | * ? DevelopmentConfigService
|
19 | * : ProductionConfigService,
|
20 | * };
|
21 | * ```
|
22 | *
|
23 | * @see [Use class](https://docs.nestjs.com/fundamentals/custom-providers#use-class)
|
24 | * @see [Injection scopes](https://docs.nestjs.com/fundamentals/injection-scopes)
|
25 | *
|
26 | * @publicApi
|
27 | */
|
28 | export interface ClassProvider<T = any> {
|
29 | /**
|
30 | * Injection token
|
31 | */
|
32 | provide: string | symbol | Type<any> | Abstract<any> | Function;
|
33 | /**
|
34 | * Type (class name) of provider (instance to be injected).
|
35 | */
|
36 | useClass: Type<T>;
|
37 | /**
|
38 | * Optional enum defining lifetime of the provider that is injected.
|
39 | */
|
40 | scope?: Scope;
|
41 | }
|
42 | /**
|
43 | * Interface defining a *Value* type provider.
|
44 | *
|
45 | * For example:
|
46 | * ```typescript
|
47 | * const connectionProvider = {
|
48 | * provide: 'CONNECTION',
|
49 | * useValue: connection,
|
50 | * };
|
51 | * ```
|
52 | *
|
53 | * @see [Use value](https://docs.nestjs.com/fundamentals/custom-providers#use-value)
|
54 | *
|
55 | * @publicApi
|
56 | */
|
57 | export interface ValueProvider<T = any> {
|
58 | /**
|
59 | * Injection token
|
60 | */
|
61 | provide: string | symbol | Type<any> | Abstract<any> | Function;
|
62 | /**
|
63 | * Instance of a provider to be injected.
|
64 | */
|
65 | useValue: T;
|
66 | }
|
67 | /**
|
68 | * Interface defining a *Factory* type provider.
|
69 | *
|
70 | * For example:
|
71 | * ```typescript
|
72 | * const connectionFactory = {
|
73 | * provide: 'CONNECTION',
|
74 | * useFactory: (optionsProvider: OptionsProvider) => {
|
75 | * const options = optionsProvider.get();
|
76 | * return new DatabaseConnection(options);
|
77 | * },
|
78 | * inject: [OptionsProvider],
|
79 | * };
|
80 | * ```
|
81 | *
|
82 | * @see [Use factory](https://docs.nestjs.com/fundamentals/custom-providers#use-factory)
|
83 | * @see [Injection scopes](https://docs.nestjs.com/fundamentals/injection-scopes)
|
84 | *
|
85 | * @publicApi
|
86 | */
|
87 | export interface FactoryProvider<T = any> {
|
88 | /**
|
89 | * Injection token
|
90 | */
|
91 | provide: string | symbol | Type<any> | Abstract<any> | Function;
|
92 | /**
|
93 | * Factory function that returns an instance of the provider to be injected.
|
94 | */
|
95 | useFactory: (...args: any[]) => T;
|
96 | /**
|
97 | * Optional list of providers to be injected into the context of the Factory function.
|
98 | */
|
99 | inject?: Array<Type<any> | string | symbol | Abstract<any> | Function>;
|
100 | /**
|
101 | * Optional enum defining lifetime of the provider that is returned by the Factory function.
|
102 | */
|
103 | scope?: Scope;
|
104 | }
|
105 | /**
|
106 | * Interface defining an *Existing* (aliased) type provider.
|
107 | *
|
108 | * For example:
|
109 | * ```typescript
|
110 | * const loggerAliasProvider = {
|
111 | * provide: 'AliasedLoggerService',
|
112 | * useExisting: LoggerService
|
113 | * };
|
114 | * ```
|
115 | *
|
116 | * @see [Use existing](https://docs.nestjs.com/fundamentals/custom-providers#use-existing)
|
117 | *
|
118 | * @publicApi
|
119 | */
|
120 | export interface ExistingProvider<T = any> {
|
121 | /**
|
122 | * Injection token
|
123 | */
|
124 | provide: string | symbol | Type<any> | Abstract<any> | Function;
|
125 | /**
|
126 | * Provider to be aliased by the Injection token.
|
127 | */
|
128 | useExisting: any;
|
129 | }
|