@adimm/x-injection 1.2.0 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +459 -270
- package/dist/index.cjs +672 -529
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +534 -640
- package/dist/index.d.ts +534 -640
- package/dist/index.js +635 -491
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Class, RequireAtLeastOne
|
|
3
|
-
|
|
4
|
-
/** The identifier of the `GlobalAppModule`. */
|
|
5
|
-
declare const GLOBAL_APP_MODULE_ID = "GlobalAppModule";
|
|
1
|
+
import { BindingConstraints, Container, BindInWhenOnFluentSyntax, BindWhenOnFluentSyntax, injectFromBase, MetadataName, MetadataTag, BindingScope } from 'inversify';
|
|
2
|
+
import { Class, RequireAtLeastOne } from 'type-fest';
|
|
6
3
|
|
|
7
4
|
declare enum InjectionScope {
|
|
8
5
|
/** When the service is resolved, the same cached resolved value will be used. */
|
|
@@ -13,810 +10,700 @@ declare enum InjectionScope {
|
|
|
13
10
|
Request = 2
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
|
|
17
|
-
declare function Injectable(scope?: InjectionScope): ClassDecorator;
|
|
18
|
-
|
|
19
|
-
interface OnEvent<T> {
|
|
20
|
-
/**
|
|
21
|
-
* Sets a binding activation handler. The activation handler is invoked after a dependency has been resolved
|
|
22
|
-
* and before it is added to a scope cache. The activation handler will not be
|
|
23
|
-
* invoked if the dependency is taken from a scope cache.
|
|
24
|
-
*/
|
|
25
|
-
activation?: BindingActivation<T>;
|
|
13
|
+
declare enum MiddlewareType {
|
|
26
14
|
/**
|
|
27
|
-
*
|
|
28
|
-
* The deactivation handler is called when the binding is unbound from a container.
|
|
29
|
-
*/
|
|
30
|
-
deactivation?: BindingDeactivation<T>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
type ProviderToken<T = any> = ProviderIdentifier<T> | DependencyProvider<T>;
|
|
34
|
-
type DependencyProvider<T = any> = Class<T> | Function | ProviderClassToken<T> | ProviderValueToken<T> | ProviderFactoryToken<T>;
|
|
35
|
-
type ProviderClassToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
|
|
36
|
-
/** The `class` to be injected. */
|
|
37
|
-
useClass: Class<T>;
|
|
38
|
-
};
|
|
39
|
-
type ProviderValueToken<T> = ProviderOptions<T> & {
|
|
40
|
-
/** The _(constant)_ `value` to be injected. */
|
|
41
|
-
useValue: T;
|
|
42
|
-
};
|
|
43
|
-
type ProviderFactoryToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
|
|
44
|
-
/**
|
|
45
|
-
* Factory `function` that returns an instance of the provider to be injected.
|
|
15
|
+
* Can be used to register a `middleware` which will be invoked right before importing a `module` into _this_ module.
|
|
46
16
|
*
|
|
47
|
-
*
|
|
48
|
-
* ```ts
|
|
49
|
-
* const connectionProvider = {
|
|
50
|
-
* provide: 'CONNECTION',
|
|
51
|
-
* useFactory: (optionsService: OptionsService, secondService: SecondService) => {
|
|
52
|
-
* const options = optionsService.get();
|
|
17
|
+
* The provided middleware `callback` can either return a `boolean` or a `ProviderModule` instance.
|
|
53
18
|
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* // `inject` is optional.
|
|
57
|
-
* inject: [OptionsService, SecondService]
|
|
58
|
-
* };
|
|
59
|
-
* ```
|
|
19
|
+
* **Note:** _Returning `true` can be used to pass through the middleware without modifying_
|
|
20
|
+
* _the `ProviderModule` instance, while returning `false` will reject the request of importing that specific module._
|
|
60
21
|
*/
|
|
61
|
-
|
|
22
|
+
BeforeAddImport = 0,
|
|
62
23
|
/**
|
|
63
|
-
*
|
|
24
|
+
* Can be used to register a `middleware` which will be invoked right before adding a provider to _this_ module.
|
|
64
25
|
*
|
|
65
|
-
*
|
|
66
|
-
*/
|
|
67
|
-
inject?: ProviderToken[];
|
|
68
|
-
};
|
|
69
|
-
type ProviderIdentifier<T = any> = Class<T> | Function | symbol | string;
|
|
70
|
-
interface ProviderOptions<T> {
|
|
71
|
-
/** The injection `token`. */
|
|
72
|
-
provide: ProviderIdentifier<T>;
|
|
73
|
-
/**
|
|
74
|
-
* Can be used to set a binding handler.
|
|
26
|
+
* The provided middleware `callback` can either return a `boolean` or a `ProviderToken` object type.
|
|
75
27
|
*
|
|
76
|
-
*
|
|
77
|
-
*
|
|
28
|
+
* **Note:** _Returning `true` can be used to pass through the middleware without modifying_
|
|
29
|
+
* _the `ProviderToken` object, while returning `false` will reject the request of adding that specific provider._
|
|
78
30
|
*/
|
|
79
|
-
|
|
31
|
+
BeforeAddProvider = 1,
|
|
80
32
|
/**
|
|
81
|
-
*
|
|
33
|
+
* Can be used to register a `middleware` which will be invoked right before a provider is returned to the consumer from _this_ module container.
|
|
82
34
|
*
|
|
83
|
-
*
|
|
35
|
+
* The provided middleware `callback` can return `anything`.
|
|
84
36
|
*/
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
interface ProviderScopeOption {
|
|
37
|
+
BeforeGet = 2,
|
|
88
38
|
/**
|
|
89
|
-
*
|
|
39
|
+
* Can be used to register a `middleware` which will be invoked right before removing an imported module from _this_ module.
|
|
90
40
|
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* See {@link https://inversify.io/docs/fundamentals/binding/#scope} for more details..
|
|
41
|
+
* **Note:** _The provided middleware `callback` must return a `boolean` where `true` means that_
|
|
42
|
+
* _the imported module can be removed and `false` means to keep it._
|
|
94
43
|
*/
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* The low-level App Container.
|
|
100
|
-
*
|
|
101
|
-
* **Internally used, please use the `AppModule` to interact with it.**
|
|
102
|
-
*/
|
|
103
|
-
declare const GlobalContainer: Container;
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Modules are highly recommended as an effective way to organize your components.
|
|
107
|
-
* For most applications, you'll likely have multiple modules, each encapsulating a closely related set of capabilities.
|
|
108
|
-
*
|
|
109
|
-
* _See {@link ProviderModuleOptions | ProviderModuleOptions}_.
|
|
110
|
-
*
|
|
111
|
-
* **Note:** _Check also the {@link IProviderModuleDefinition}._
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```ts
|
|
115
|
-
* const EngineModule = new ProviderModule({
|
|
116
|
-
* identifier: Symbol('EngineModule'),
|
|
117
|
-
* providers: [EngineService],
|
|
118
|
-
* exports: [EngineService]
|
|
119
|
-
* });
|
|
120
|
-
*
|
|
121
|
-
* const DashboardModule = new ProviderModule({
|
|
122
|
-
* identifier: Symbol('DashboardModule'),
|
|
123
|
-
* providers: [DashboardService],
|
|
124
|
-
* exports: [DashboardService]
|
|
125
|
-
* });
|
|
126
|
-
*
|
|
127
|
-
* const CarModule = new ProviderModule({
|
|
128
|
-
* identifier: Symbol('CarModule'),
|
|
129
|
-
* imports: [EngineModule, DashboardModule],
|
|
130
|
-
* providers: [CarService],
|
|
131
|
-
* exports: [CarService]
|
|
132
|
-
* });
|
|
133
|
-
*
|
|
134
|
-
* // Run-time class replacement:
|
|
135
|
-
* const RedCarModule = new ProviderModule({
|
|
136
|
-
* identifier: Symbol('RedCarModule'),
|
|
137
|
-
* imports: [CarModule],
|
|
138
|
-
* providers: [
|
|
139
|
-
* {
|
|
140
|
-
* provide: CarService,
|
|
141
|
-
* useClass: RedCarService,
|
|
142
|
-
* }
|
|
143
|
-
* ],
|
|
144
|
-
* });
|
|
145
|
-
*
|
|
146
|
-
* // Run-time factory example:
|
|
147
|
-
* const BlackCarModule = new ProviderModule({
|
|
148
|
-
* identifier: Symbol('BlackCarModule'),
|
|
149
|
-
* imports: [CarModule],
|
|
150
|
-
* providers: [
|
|
151
|
-
* {
|
|
152
|
-
* provide: CarService,
|
|
153
|
-
* useFactory: (carService: CarService) => {
|
|
154
|
-
* carService.setColor('black');
|
|
155
|
-
*
|
|
156
|
-
* return carService;
|
|
157
|
-
* },
|
|
158
|
-
* inject: [CarService]
|
|
159
|
-
* }
|
|
160
|
-
* ],
|
|
161
|
-
* });
|
|
162
|
-
* ```
|
|
163
|
-
*/
|
|
164
|
-
declare class ProviderModule implements IProviderModule {
|
|
165
|
-
isDisposed: boolean;
|
|
166
|
-
readonly identifier: ModuleIdentifier;
|
|
167
|
-
isGlobal: boolean;
|
|
168
|
-
protected isAppModule: IProviderModuleNaked['isAppModule'];
|
|
169
|
-
protected instantiatedFromDefinition: IProviderModuleNaked['instantiatedFromDefinition'];
|
|
170
|
-
protected container: Container;
|
|
171
|
-
protected defaultScope: IProviderModuleNaked['defaultScope'];
|
|
172
|
-
protected onReady: IProviderModuleNaked['onReady'];
|
|
173
|
-
protected onDispose: IProviderModuleNaked['onDispose'];
|
|
174
|
-
protected moduleUtils: IProviderModuleNaked['moduleUtils'];
|
|
175
|
-
protected imports: IProviderModuleNaked['imports'];
|
|
176
|
-
protected providers: IProviderModuleNaked['providers'];
|
|
177
|
-
protected exports: IProviderModuleNaked['exports'];
|
|
178
|
-
protected registeredSideEffects: IProviderModuleNaked['registeredSideEffects'];
|
|
179
|
-
constructor(options: ProviderModuleOptions | IProviderModuleDefinition);
|
|
180
|
-
get<T>(provider: ProviderToken<T>, isOptional?: boolean): T;
|
|
181
|
-
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
|
|
182
|
-
lazyImport(...modules: ProviderModuleOrDefinition[]): void;
|
|
183
|
-
toNaked(): IProviderModuleNaked;
|
|
184
|
-
dispose(): Promise<void>;
|
|
185
|
-
toString(): string;
|
|
186
|
-
private setIdentifier;
|
|
187
|
-
private prepareContainer;
|
|
188
|
-
private injectImportedModules;
|
|
189
|
-
private injectProviders;
|
|
190
|
-
private registerSideEffect;
|
|
191
|
-
private invokeRegisteredSideEffects;
|
|
192
|
-
private removeRegisteredSideEffects;
|
|
193
|
-
private shouldThrowIfDisposed;
|
|
44
|
+
BeforeRemoveImport = 3,
|
|
194
45
|
/**
|
|
195
|
-
*
|
|
46
|
+
* Can be used to register a `middleware` which will be invoked right before removing a provider from _this_ module.
|
|
196
47
|
*
|
|
197
|
-
*
|
|
48
|
+
* **Note:** _The provided middleware `callback` must return a `boolean` where `true` means that_
|
|
49
|
+
* _the provider can be removed and `false` means to keep it._
|
|
198
50
|
*/
|
|
199
|
-
|
|
51
|
+
BeforeRemoveProvider = 4,
|
|
200
52
|
/**
|
|
201
|
-
*
|
|
53
|
+
* Can be used to register a `middleware` which will be invoked right before removing an `ExportDefinition` from _this_ module.
|
|
202
54
|
*
|
|
203
|
-
*
|
|
55
|
+
* **Note:** _The provided middleware `callback` must return a `boolean` where `true` means that_
|
|
56
|
+
* _the `ExportDefinition` can be removed and `false` means to keep it._
|
|
204
57
|
*/
|
|
205
|
-
|
|
58
|
+
BeforeRemoveExport = 5,
|
|
206
59
|
/**
|
|
207
|
-
*
|
|
60
|
+
* Can be used to register a `middleware` which will be invoked each time
|
|
61
|
+
* a _consumer_ `module` tries to access the `ExportDefinition` list of _this_ module to `get` a provider.
|
|
208
62
|
*
|
|
209
|
-
*
|
|
63
|
+
* **Note:** _The provided middleware `callback` will be invoked for each `ProviderToken` of the `ExportsDefinition` list_
|
|
64
|
+
* _and must return a `boolean` where `true` means that the `ProviderToken` is authorized to be used by the importer module._
|
|
210
65
|
*/
|
|
211
|
-
|
|
66
|
+
OnExportAccess = 6
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
declare enum DefinitionEventType {
|
|
70
|
+
/** No-Operation, yet. */
|
|
71
|
+
Noop = 0,
|
|
212
72
|
/**
|
|
213
|
-
*
|
|
73
|
+
* A new `module` or `blueprint` has been added.
|
|
214
74
|
*
|
|
215
|
-
*
|
|
75
|
+
* **Note:** _The occurred change type is: `ModuleOrBlueprint`_
|
|
216
76
|
*/
|
|
217
|
-
|
|
77
|
+
Import = 1,
|
|
218
78
|
/**
|
|
219
|
-
*
|
|
79
|
+
* A new `provider` has been added.
|
|
220
80
|
*
|
|
221
|
-
*
|
|
81
|
+
* **Note:** _The occurred change type is: `DependencyProvider`_
|
|
222
82
|
*/
|
|
223
|
-
|
|
83
|
+
Provider = 2,
|
|
224
84
|
/**
|
|
225
|
-
*
|
|
85
|
+
* A `module` is retrieving from its container a `provider`.
|
|
226
86
|
*
|
|
227
|
-
*
|
|
87
|
+
* **Note:** _The occurred change type is: `any`_
|
|
228
88
|
*/
|
|
229
|
-
|
|
89
|
+
GetProvider = 3,
|
|
230
90
|
/**
|
|
231
|
-
*
|
|
91
|
+
* A new `module` or `provider` has been added to the `exports` definition.
|
|
232
92
|
*
|
|
233
|
-
*
|
|
93
|
+
* **Note:** _The occurred change type is: `ExportDefinition`_
|
|
234
94
|
*/
|
|
235
|
-
|
|
95
|
+
Export = 4,
|
|
236
96
|
/**
|
|
237
|
-
*
|
|
97
|
+
* A new `module` or `blueprint` has been added to the `exports` definition.
|
|
238
98
|
*
|
|
239
|
-
*
|
|
99
|
+
* **Note:** _The occurred change type is: `ModuleOrBlueprint`_
|
|
240
100
|
*/
|
|
241
|
-
|
|
101
|
+
ExportModule = 5,
|
|
242
102
|
/**
|
|
243
|
-
*
|
|
103
|
+
* A new `provider` has been added to the `exports` definition.
|
|
244
104
|
*
|
|
245
|
-
*
|
|
105
|
+
* **Note:** _The occurred change type is: `ProviderToken`_
|
|
246
106
|
*/
|
|
247
|
-
|
|
107
|
+
ExportProvider = 6,
|
|
248
108
|
/**
|
|
249
|
-
*
|
|
109
|
+
* A `module` has been removed.
|
|
250
110
|
*
|
|
251
|
-
*
|
|
111
|
+
* **Note:** _The occurred change type is: `IProviderModule`_
|
|
252
112
|
*/
|
|
253
|
-
|
|
113
|
+
ImportRemoved = 7,
|
|
254
114
|
/**
|
|
255
|
-
*
|
|
115
|
+
* A `provider` has been removed.
|
|
256
116
|
*
|
|
257
|
-
*
|
|
117
|
+
* **Note:** _The occurred change type is: `DependencyProvider`_
|
|
258
118
|
*/
|
|
259
|
-
|
|
119
|
+
ProviderRemoved = 8,
|
|
260
120
|
/**
|
|
261
|
-
*
|
|
121
|
+
* An `ExportDefinition` has been removed.
|
|
262
122
|
*
|
|
263
|
-
*
|
|
123
|
+
* **Note:** _The occurred change type is: `ExportDefinition`_
|
|
264
124
|
*/
|
|
265
|
-
|
|
125
|
+
ExportRemoved = 9,
|
|
266
126
|
/**
|
|
267
|
-
*
|
|
127
|
+
* A `module` has been removed from the `export` definition.
|
|
268
128
|
*
|
|
269
|
-
*
|
|
129
|
+
* **Note:** _The occurred change type is: `IProviderModule`_
|
|
270
130
|
*/
|
|
271
|
-
|
|
131
|
+
ExportModuleRemoved = 10,
|
|
272
132
|
/**
|
|
273
|
-
*
|
|
133
|
+
* A `provider` has been removed from the `export` definition.
|
|
274
134
|
*
|
|
275
|
-
*
|
|
135
|
+
* **Note:** _The occurred change type is: `ProviderToken`_
|
|
276
136
|
*/
|
|
277
|
-
|
|
137
|
+
ExportProviderRemoved = 11
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** See {@link https://inversify.io/docs/api/decorator/#injectable} for more details. */
|
|
141
|
+
declare function Injectable(scope?: InjectionScope): ClassDecorator;
|
|
142
|
+
|
|
143
|
+
type AsyncMethod<T = void> = () => Promise<T>;
|
|
144
|
+
|
|
145
|
+
type ProviderToken<T = any> = ProviderIdentifier<T> | DependencyProvider<T>;
|
|
146
|
+
type DependencyProvider<T = any> = Class<T> | Function | ProviderClassToken<T> | ProviderValueToken<T> | ProviderFactoryToken<T>;
|
|
147
|
+
type ProviderClassToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
|
|
148
|
+
/** The `class` to be injected. */
|
|
149
|
+
useClass: Class<T>;
|
|
150
|
+
};
|
|
151
|
+
type ProviderValueToken<T> = ProviderOptions<T> & {
|
|
152
|
+
/** The _(constant)_ `value` to be injected. */
|
|
153
|
+
useValue: T;
|
|
154
|
+
};
|
|
155
|
+
type ProviderFactoryToken<T> = (ProviderOptions<T> & ProviderScopeOption) & {
|
|
278
156
|
/**
|
|
279
|
-
*
|
|
157
|
+
* Factory `function` that returns an instance of the provider to be injected.
|
|
280
158
|
*
|
|
281
|
-
*
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```ts
|
|
161
|
+
* const connectionProvider = {
|
|
162
|
+
* provide: 'CONNECTION',
|
|
163
|
+
* useFactory: (optionsService: OptionsService, secondService: SecondService) => {
|
|
164
|
+
* const options = optionsService.get();
|
|
286
165
|
*
|
|
287
|
-
*
|
|
166
|
+
* return new DatabaseConnection(options);
|
|
167
|
+
* },
|
|
168
|
+
* // `inject` is optional.
|
|
169
|
+
* inject: [OptionsService, SecondService]
|
|
170
|
+
* };
|
|
171
|
+
* ```
|
|
288
172
|
*/
|
|
289
|
-
|
|
173
|
+
useFactory: (...providers: any[]) => T;
|
|
290
174
|
/**
|
|
291
|
-
*
|
|
175
|
+
* Optional list of providers to be injected into the context of the Factory `function`.
|
|
292
176
|
*
|
|
293
|
-
*
|
|
294
|
-
*/
|
|
295
|
-
protected __rebindSync<T>(provider: ProviderToken<T>): BindToFluentSyntax<T>;
|
|
296
|
-
/**
|
|
297
|
-
* **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
|
|
177
|
+
* **Note:** _The current module container context is available too._
|
|
298
178
|
*
|
|
299
|
-
*
|
|
179
|
+
* ```ts
|
|
180
|
+
* ProviderModule.create({
|
|
181
|
+
* id: 'FactoryProviderModule',
|
|
182
|
+
* providers: [
|
|
183
|
+
* DatabaseService,
|
|
184
|
+
* {
|
|
185
|
+
* provide: 'DATABASE_SECRET',
|
|
186
|
+
* useFactory: (dbService: DatabaseService) => {
|
|
187
|
+
* // Here you have access to the already resolved `DatabaseService` of the `FactoryProviderModule`.
|
|
188
|
+
* return dbService.getSecret();
|
|
189
|
+
* },
|
|
190
|
+
* inject: [DatabaseService]
|
|
191
|
+
* }
|
|
192
|
+
* ]
|
|
193
|
+
* });
|
|
194
|
+
* ```
|
|
300
195
|
*/
|
|
301
|
-
|
|
196
|
+
inject?: ProviderIdentifier[];
|
|
197
|
+
};
|
|
198
|
+
type ProviderIdentifier<T = any> = Class<T> | Function | symbol | string;
|
|
199
|
+
interface ProviderOptions<T> {
|
|
200
|
+
/** The injection `token`. */
|
|
201
|
+
provide: ProviderIdentifier<T>;
|
|
302
202
|
/**
|
|
303
|
-
*
|
|
203
|
+
* Specifies whether the binding is used to provide a resolved value for the given {@link ProviderToken | provider}.
|
|
304
204
|
*
|
|
305
|
-
* See {@link
|
|
205
|
+
* See {@link https://inversify.io/docs/api/binding-syntax/#bindwhenfluentsyntax} for more details.
|
|
306
206
|
*/
|
|
307
|
-
|
|
207
|
+
when?: (metadata: BindingConstraints) => boolean;
|
|
208
|
+
}
|
|
209
|
+
interface ProviderScopeOption {
|
|
308
210
|
/**
|
|
309
|
-
*
|
|
211
|
+
* The scope determines the caching strategy used to decide whether the service should be resolved or a cached value should be provided.
|
|
212
|
+
*
|
|
213
|
+
* If not provided, it'll default to the `ProviderModule` default scope.
|
|
310
214
|
*
|
|
311
|
-
* See {@link
|
|
215
|
+
* See {@link https://inversify.io/docs/fundamentals/binding/#scope} for more details..
|
|
312
216
|
*/
|
|
313
|
-
|
|
217
|
+
scope?: InjectionScope;
|
|
314
218
|
}
|
|
315
219
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
register<AsNaked extends boolean = false>(options: AppModuleOptions): AsNaked extends false ? IAppModule : IAppModule & IProviderModuleNaked;
|
|
327
|
-
lazyImport(...modules: ProviderModuleOrDefinition[]): void;
|
|
328
|
-
toNaked(): IAppModule & IProviderModuleNaked;
|
|
329
|
-
dispose(): Promise<void>;
|
|
330
|
-
/** **Internally used, do not use!** */
|
|
331
|
-
_importWithoutSecondaryImportCheck(...modules: ProviderModuleOrDefinition[]): void;
|
|
332
|
-
private checkIfRegisteredModulesHaveGlobalMark;
|
|
220
|
+
declare class ModuleContainer {
|
|
221
|
+
readonly container: Container;
|
|
222
|
+
private readonly providerModule;
|
|
223
|
+
constructor(providerModule: ProviderModule, inversifyParentContainer?: Container);
|
|
224
|
+
get<T, IsOptional extends boolean | undefined = undefined, AsList extends boolean | undefined = undefined>(provider: ProviderToken<T>, isOptional?: IsOptional, asList?: AsList): ProviderModuleGetReturn<T, IsOptional, AsList>;
|
|
225
|
+
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManyReturn<D>;
|
|
226
|
+
bindToContainer<T>(provider: DependencyProvider<T>): void;
|
|
227
|
+
setBindingScope<T>(provider: ProviderToken<T>, binding: BindInWhenOnFluentSyntax<T>): BindWhenOnFluentSyntax<T>;
|
|
228
|
+
dispose(): void;
|
|
229
|
+
private getProvider;
|
|
333
230
|
}
|
|
334
|
-
/**
|
|
335
|
-
* Special instance of {@link ProviderModule} which acts as the global module of your application in which you can inject any provider
|
|
336
|
-
* which must be available through your entire application.
|
|
337
|
-
*
|
|
338
|
-
* The registered providers will automatically be available inside all the modules.
|
|
339
|
-
*
|
|
340
|
-
* @example
|
|
341
|
-
* ```ts
|
|
342
|
-
* // The `register` method must be invoked only once during your application life cycle!
|
|
343
|
-
* AppModule.register({
|
|
344
|
-
* imports: [ConfigModule, ApiModule, UserModule, DatabaseModule],
|
|
345
|
-
* providers: [DummyService],
|
|
346
|
-
* });
|
|
347
|
-
* ```
|
|
348
|
-
*/
|
|
349
|
-
declare const AppModule: GlobalAppModule;
|
|
350
231
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
* GarageModuleDefinition.imports = [...GarageModuleDefinition.imports, PorscheModule, FerrariModuleDefinition];
|
|
365
|
-
*
|
|
366
|
-
* // ...
|
|
367
|
-
*
|
|
368
|
-
* const GarageModule = new ProviderModule(GarageModuleDefinition);
|
|
369
|
-
*
|
|
370
|
-
* // or
|
|
371
|
-
*
|
|
372
|
-
* ExistingModule.lazyImport(GarageModuleDefinition);
|
|
373
|
-
* ```
|
|
374
|
-
*
|
|
375
|
-
* **Note:** _This means that you can't expect to be able to inject dependencies from a {@link ProviderModuleDefinition}_
|
|
376
|
-
* _as how you would do with an instance of a `ProviderModule`._
|
|
377
|
-
*/
|
|
378
|
-
declare class ProviderModuleDefinition implements IProviderModuleDefinition {
|
|
379
|
-
identifier: IProviderModuleDefinition['identifier'];
|
|
380
|
-
imports: IProviderModuleDefinition['imports'];
|
|
381
|
-
providers: IProviderModuleDefinition['providers'];
|
|
382
|
-
exports: IProviderModuleDefinition['exports'];
|
|
383
|
-
defaultScope: IProviderModuleDefinition['defaultScope'];
|
|
384
|
-
isGlobal: IProviderModuleDefinition['isGlobal'];
|
|
385
|
-
onReady: IProviderModuleDefinition['onReady'];
|
|
386
|
-
onDispose: IProviderModuleDefinition['onDispose'];
|
|
387
|
-
constructor(moduleOptions: ProviderModuleOptions);
|
|
388
|
-
getDefinition(): ProviderModuleOptions;
|
|
389
|
-
clone(definition?: Partial<ProviderModuleOptions>): IProviderModuleDefinition;
|
|
390
|
-
toString(): string;
|
|
391
|
-
private checkIfShouldBeAddedToTheGlobalRegister;
|
|
232
|
+
declare class ImportedModuleContainer {
|
|
233
|
+
get moduleDef(): ModuleDefinition<true>;
|
|
234
|
+
/** The {@link ProviderModule} which imported {@link providerModule | this} module. */
|
|
235
|
+
private readonly importedIntoModule;
|
|
236
|
+
private readonly providerModule;
|
|
237
|
+
private readonly proxyContainer;
|
|
238
|
+
private proxyContainerOptions;
|
|
239
|
+
constructor(importedIntoModule: ProviderModule, providerModule: ProviderModule);
|
|
240
|
+
dispose(): void;
|
|
241
|
+
private buildProxyContainer;
|
|
242
|
+
private proxyProviderIdentifier;
|
|
243
|
+
private unproxyProviderIdentifier;
|
|
244
|
+
private traverseExportGraph;
|
|
392
245
|
}
|
|
393
246
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
*
|
|
247
|
+
declare class Signal<T> {
|
|
248
|
+
private value;
|
|
249
|
+
private readonly subscribers;
|
|
250
|
+
constructor(initialValue: T);
|
|
251
|
+
/** Can be used to `emit` a _new_ value and notify the _subscribers_. */
|
|
252
|
+
emit(newValue: T): void;
|
|
253
|
+
/** Can be used to retrieve the _current_ value of the {@link Signal} imperatively. */
|
|
254
|
+
get(): T;
|
|
255
|
+
/**
|
|
256
|
+
* Can be used to `subscribe` to the emitted values of this {@link Signal}.
|
|
404
257
|
*
|
|
405
|
-
*
|
|
258
|
+
* @param callback The `callback` which will be invoked when a _new_ value is emitted.
|
|
259
|
+
* @param invokeImmediately When set to `true` it'll invoke the provided {@link callback} immediately with the latest value available. _(defaults to `false`)_
|
|
406
260
|
*/
|
|
407
|
-
|
|
261
|
+
subscribe(callback: SignalCallback<T>, invokeImmediately?: boolean): () => void;
|
|
262
|
+
/** Disposes of the internal references. */
|
|
263
|
+
dispose(): void;
|
|
264
|
+
}
|
|
265
|
+
type SignalCallback<T> = (value: T) => void | Promise<void>;
|
|
266
|
+
|
|
267
|
+
interface IDynamicModuleDefinition {
|
|
268
|
+
/** Can be used to _subscribe_ in real-time to the _definition_ changes. */
|
|
269
|
+
readonly subscribe: Signal<DefinitionEvent>['subscribe'];
|
|
408
270
|
/**
|
|
409
|
-
*
|
|
271
|
+
* Can be used to `import` a new {@link moduleOrBlueprint} into the current {@link IProviderModule | Module}.
|
|
410
272
|
*
|
|
411
|
-
*
|
|
273
|
+
* @param moduleOrBlueprint Either the `Module` or the `ModuleBlueprint` to be imported.
|
|
274
|
+
* @param addToExports When set to `true` it'll also `export` the {@link moduleOrBlueprint}. _(defaults to `false`)_
|
|
412
275
|
*/
|
|
413
|
-
|
|
276
|
+
addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
|
|
414
277
|
/**
|
|
415
|
-
*
|
|
278
|
+
* Can be used to _lazily_ `import` a new {@link module} into the current {@link IProviderModule | Module}.
|
|
416
279
|
*
|
|
417
|
-
* **Note:**
|
|
280
|
+
* **Note:** _This is useful when you want to lazy import a module from within another file._
|
|
418
281
|
*
|
|
419
|
-
*
|
|
420
|
-
*
|
|
421
|
-
*
|
|
282
|
+
* ```ts
|
|
283
|
+
* addImportLazy(async () => import('./lazy.module'));
|
|
284
|
+
* ```
|
|
422
285
|
*
|
|
423
|
-
*
|
|
286
|
+
* @param lazyCb An `async` callback which will resolve the {@link IProviderModule | Module} to be imported.
|
|
287
|
+
* @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
|
|
424
288
|
*/
|
|
425
|
-
|
|
289
|
+
addImportLazy(lazyCb: AsyncMethod<IProviderModule>, addToExports?: boolean): Promise<void>;
|
|
426
290
|
/**
|
|
427
|
-
*
|
|
428
|
-
* and the providers resolved.
|
|
429
|
-
*
|
|
430
|
-
* **This happens only once, when the {@link IProviderModule | ProviderModule} has been bootstrapped!**
|
|
291
|
+
* Can be used to `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
|
|
431
292
|
*
|
|
432
|
-
* @param
|
|
293
|
+
* @param provider The {@link DependencyProvider | Provider} to add.
|
|
294
|
+
* @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
|
|
433
295
|
*/
|
|
434
|
-
|
|
296
|
+
addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
|
|
435
297
|
/**
|
|
436
|
-
*
|
|
298
|
+
* Can be used to _lazily_ `bind` a new {@link provider} to the {@link IProviderModule | Module}'s `container`.
|
|
299
|
+
*
|
|
300
|
+
* **Note:** _This is useful when you want to lazy import a provider from within another file._
|
|
437
301
|
*
|
|
438
|
-
*
|
|
302
|
+
* ```ts
|
|
303
|
+
* addImportLazy(async () => import('./lazy.provider'));
|
|
304
|
+
* ```
|
|
305
|
+
*
|
|
306
|
+
* @param lazyCb An `async` callback which will resolve the {@link DependencyProvider | Provider} to add.
|
|
307
|
+
* @param addToExports When set to `true` it'll also `export` the {@link module}. _(defaults to `false`)_
|
|
439
308
|
*/
|
|
440
|
-
|
|
441
|
-
}
|
|
442
|
-
interface ProviderModuleOptionsInternal {
|
|
443
|
-
isAppModule?: boolean;
|
|
444
|
-
instantiatedFromDefinition?: boolean;
|
|
445
|
-
isDisposed?: boolean;
|
|
446
|
-
/** Can be used to manually provide the {@link IAppModule} instance. */
|
|
447
|
-
appModule?: () => GlobalAppModule;
|
|
448
|
-
/** Can be used to manually provide a {@link Container} instance. */
|
|
449
|
-
container?: () => Container;
|
|
450
|
-
}
|
|
451
|
-
type ExportsList = (StaticExport | LazyExport)[];
|
|
452
|
-
type StaticExport = ProviderToken | ProviderModuleOrDefinition;
|
|
453
|
-
type LazyExport = (
|
|
454
|
-
/** The {@link IProviderModule | module} which is importing _this_ module. */
|
|
455
|
-
importerModule: IProviderModule) => StaticExport | void;
|
|
456
|
-
type OnDisposeOptions = RequireAtLeastOne<{
|
|
309
|
+
addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
|
|
457
310
|
/**
|
|
458
|
-
*
|
|
311
|
+
* Can be used to remove an `import` from the _current_ {@link IProviderModule | Module}.
|
|
312
|
+
* It'll also automatically remove it from the `exports` definition.
|
|
459
313
|
*
|
|
460
|
-
*
|
|
314
|
+
* **Note:** _You can always add it back with the {@link addImport} or {@link addImportLazy} methods._
|
|
315
|
+
*
|
|
316
|
+
* @param module The {@link IProviderModule | Module} to be removed.
|
|
461
317
|
*/
|
|
462
|
-
|
|
318
|
+
removeImport(module: IProviderModule): boolean;
|
|
463
319
|
/**
|
|
464
|
-
*
|
|
320
|
+
* Can be used to remove a `provider` from the _current_ {@link IProviderModule | Module}'s `container`.
|
|
321
|
+
* It'll also automatically remove it from the `exports` definition.
|
|
465
322
|
*
|
|
466
|
-
* **Note:**
|
|
323
|
+
* **Note:** _You can always add it back with the {@link addProvider} or {@link addProviderLazy} methods._
|
|
467
324
|
*
|
|
468
|
-
* @param
|
|
325
|
+
* @param provider The {@link DependencyProvider | Provider} to be removed.
|
|
469
326
|
*/
|
|
470
|
-
|
|
471
|
-
}>;
|
|
472
|
-
|
|
473
|
-
interface IProviderModuleDefinition extends ProviderModuleOptions {
|
|
474
|
-
/** Returns the {@link ProviderModuleOptions | definition}. */
|
|
475
|
-
getDefinition(): ProviderModuleOptions;
|
|
327
|
+
removeProvider<T>(provider: DependencyProvider<T>): boolean;
|
|
476
328
|
/**
|
|
477
|
-
* Can be used to
|
|
329
|
+
* Can be used to remove a {@link IProviderModule | Module} or {@link DependencyProvider | Provider} from
|
|
330
|
+
* the `exports` definition of this `module`.
|
|
478
331
|
*
|
|
479
|
-
*
|
|
332
|
+
* **Note:** _Consumers which already consumed the {@link exportDefinition} may still old a reference onto it._
|
|
480
333
|
*
|
|
481
|
-
*
|
|
482
|
-
* const CarModuleDefinition = new ProviderModuleDefinition({
|
|
483
|
-
* identifier: 'CarModuleDefinition',
|
|
484
|
-
* providers: [CarService],
|
|
485
|
-
* });
|
|
486
|
-
*
|
|
487
|
-
* const CarModuleDefinitionMocked = CarModuleDefinition.clone({
|
|
488
|
-
* identifier: 'CarModuleDefinitionMocked',
|
|
489
|
-
* providers: [{ provide: CarService, useClass: CarServiceMocked }]
|
|
490
|
-
* });
|
|
491
|
-
* ```
|
|
334
|
+
* @param exportDefinition The {@link ExportDefinition} to be removed.
|
|
492
335
|
*/
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
336
|
+
removeFromExports(exportDefinition: ExportDefinition): boolean;
|
|
337
|
+
}
|
|
338
|
+
interface DefinitionEvent {
|
|
339
|
+
/** The {@link DefinitionEventType}. */
|
|
340
|
+
type: DefinitionEventType;
|
|
341
|
+
/** The occurred change. */
|
|
342
|
+
change: any;
|
|
496
343
|
}
|
|
497
344
|
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
*/
|
|
521
|
-
bindToContainer<T>(provider: DependencyProvider<T>, defaultScope: InjectionScope): boolean;
|
|
522
|
-
private checkIfShouldBeAddedToTheGlobalRegister;
|
|
523
|
-
private bindSelfTokenToContainer;
|
|
524
|
-
private bindClassTokenToContainer;
|
|
525
|
-
private bindValueTokenToContainer;
|
|
526
|
-
private bindFactoryTokenToContainer;
|
|
527
|
-
/** Sets the {@link InjectionScope} of a bound {@link provider}. */
|
|
528
|
-
private setBindingScope;
|
|
529
|
-
/** Sets the `when` clause of a bound {@link provider}. */
|
|
530
|
-
private setWhenBinding;
|
|
531
|
-
/** Sets the `activation` and `deactivation` events of a bound {@link provider}. */
|
|
532
|
-
private setBindingOnEvent;
|
|
345
|
+
declare class DynamicModuleDefinition implements IDynamicModuleDefinition {
|
|
346
|
+
get moduleContainer(): ModuleContainer;
|
|
347
|
+
get subscribe(): IDynamicModuleDefinition['subscribe'];
|
|
348
|
+
readonly moduleDef: ModuleDefinition<true>;
|
|
349
|
+
readonly event$: Signal<DefinitionEvent>;
|
|
350
|
+
private readonly providerModule;
|
|
351
|
+
private emittingModules;
|
|
352
|
+
private importedModuleSubscriptions;
|
|
353
|
+
constructor(providerModule: ProviderModule);
|
|
354
|
+
addImport(moduleOrBlueprint: ModuleOrBlueprint, addToExports?: boolean): void;
|
|
355
|
+
addImportLazy(lazyCb: AsyncMethod<ProviderModule>, addToExports?: boolean): Promise<void>;
|
|
356
|
+
addProvider<T>(provider: DependencyProvider<T>, addToExports?: boolean): void;
|
|
357
|
+
addProviderLazy<T>(lazyCb: AsyncMethod<DependencyProvider<T>>, addToExports?: boolean): Promise<void>;
|
|
358
|
+
removeImport(module: IProviderModule): boolean;
|
|
359
|
+
removeProvider<T>(provider: DependencyProvider<T>): boolean;
|
|
360
|
+
removeFromExports(exportDefinition: ExportDefinition): boolean;
|
|
361
|
+
emitEventSafely(event: DefinitionEvent): void;
|
|
362
|
+
dispose(): void;
|
|
363
|
+
private buildInitialDefinition;
|
|
364
|
+
private createImportedModuleContainer;
|
|
365
|
+
private subscribeToImportedModuleEvents;
|
|
366
|
+
private unsubscribeFromImportedModuleEvents;
|
|
533
367
|
}
|
|
534
368
|
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
/** The {@link DependencyProvider | providers} resolved by this module. */
|
|
553
|
-
readonly providers: DependencyProvider[];
|
|
554
|
-
/** What is exported into this module. */
|
|
555
|
-
readonly imports: ProviderModuleOrDefinition[];
|
|
556
|
-
/** What is exported from this module. */
|
|
557
|
-
readonly exports: ExportsList;
|
|
558
|
-
/** The registered `callback` which will be invoked when the internal initialization process has been completed. */
|
|
559
|
-
readonly onReady: ProviderModuleOptions['onReady'];
|
|
560
|
-
/** The registered `callback` which will be invoked when the {@link _dispose} method is invoked. */
|
|
561
|
-
readonly onDispose: ProviderModuleOptions['onDispose'];
|
|
562
|
-
readonly registeredSideEffects: RegisteredSideEffects;
|
|
563
|
-
/** It'll _completely_ re-init the `module` with the provided {@link InternalInitOptions | options}. */
|
|
564
|
-
_internalInit(options: InternalInitOptions): IProviderModule;
|
|
565
|
-
/**
|
|
566
|
-
* Can be used to execute the provided {@link cb | callback} whenever a _new_ {@link https://inversify.io/docs/fundamentals/binding/ | binding}
|
|
567
|
-
* is registered for the {@link provider}.
|
|
568
|
-
*
|
|
569
|
-
* @param provider The {@link ProviderToken}.
|
|
570
|
-
* @param cb The `callback` to be invoked.
|
|
571
|
-
*/
|
|
572
|
-
_onBind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
|
|
369
|
+
interface IMiddlewaresManager {
|
|
370
|
+
/** See {@link MiddlewareType} for more info. */
|
|
371
|
+
add<T extends MiddlewareType>(type: T, cb: AddMiddlewareCallbackType<T>): void;
|
|
372
|
+
}
|
|
373
|
+
type AddMiddlewareCallbackType<T extends MiddlewareType> = T extends MiddlewareType.BeforeAddImport ? (module: IProviderModule) => IProviderModule | boolean : T extends MiddlewareType.BeforeAddProvider ? (provider: ProviderToken) => ProviderToken | boolean : T extends MiddlewareType.BeforeGet ? (provider: any, providerToken: ProviderToken, inject: ModuleContainer['getProvider']) => any : T extends MiddlewareType.BeforeRemoveImport ? (module: IProviderModule) => boolean : T extends MiddlewareType.BeforeRemoveProvider ? (dependencyProvider: DependencyProvider<any>) => boolean : T extends MiddlewareType.BeforeRemoveExport ? (providerOrModule: ExportDefinition) => boolean : T extends MiddlewareType.OnExportAccess ? (importerModule: IProviderModule, currentExport: ProviderToken) => boolean : never;
|
|
374
|
+
|
|
375
|
+
declare class MiddlewaresManager implements IMiddlewaresManager {
|
|
376
|
+
private middlewaresMap;
|
|
377
|
+
private readonly providerModule;
|
|
378
|
+
constructor(providerModule: ProviderModule);
|
|
379
|
+
add<T extends MiddlewareType>(type: MiddlewareType, cb: AddMiddlewareCallbackType<T>): void;
|
|
380
|
+
applyMiddlewares<T>(type: MiddlewareType, ...args: any[]): T;
|
|
381
|
+
clear(): void;
|
|
382
|
+
dispose(): void;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
interface ModuleBlueprintOptions {
|
|
573
386
|
/**
|
|
574
|
-
*
|
|
575
|
-
*
|
|
387
|
+
* When set to `false` you'll have to _manually_ import this blueprint
|
|
388
|
+
* into the `AppModule` to make it available across all your modules.
|
|
576
389
|
*
|
|
577
|
-
*
|
|
578
|
-
* @param once When set to `true` it'll invoke the provided {@link cb | callback} only once.
|
|
579
|
-
* @param cb The `callback` to be invoked.
|
|
390
|
+
* Defaults to `true`.
|
|
580
391
|
*/
|
|
581
|
-
|
|
392
|
+
autoImportIntoAppModuleWhenGlobal?: boolean;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
declare class ProviderModuleBlueprint {
|
|
396
|
+
id: ProviderModuleOptions['id'];
|
|
397
|
+
imports?: ProviderModuleOptions['imports'];
|
|
398
|
+
providers?: ProviderModuleOptions['providers'];
|
|
399
|
+
exports?: ProviderModuleOptions['exports'];
|
|
400
|
+
defaultScope?: ProviderModuleOptions['defaultScope'];
|
|
401
|
+
isGlobal?: ProviderModuleOptions['isGlobal'];
|
|
402
|
+
onReady?: ProviderModuleOptions['onReady'];
|
|
403
|
+
onReset?: ProviderModuleOptions['onReset'];
|
|
404
|
+
onDispose?: ProviderModuleOptions['onDispose'];
|
|
405
|
+
private readonly blueprintOptions;
|
|
406
|
+
constructor(options: ProviderModuleOptions, blueprintOptions?: ModuleBlueprintOptions);
|
|
407
|
+
/** Can be used to update the {@link ProviderModuleBlueprint | Blueprint} definition. */
|
|
408
|
+
updateDefinition(options: ProviderModuleOptions): this;
|
|
409
|
+
/** Returns the {@link ProviderModuleOptions} of this {@link ProviderModuleBlueprint | Blueprint}. */
|
|
410
|
+
getDefinition(): ProviderModuleOptions;
|
|
582
411
|
/**
|
|
583
|
-
* Can be used to
|
|
584
|
-
* is re-registered for the {@link provider}.
|
|
412
|
+
* Can be used to instantiate a _new_ `blueprint` with the same exact options as _this_ one.
|
|
585
413
|
*
|
|
586
|
-
*
|
|
587
|
-
* @param cb The `callback` to be invoked.
|
|
414
|
+
* **Note:** _Everything is deep cloned, you can safely overwrite all the properties of the cloned instance._
|
|
588
415
|
*/
|
|
589
|
-
|
|
416
|
+
clone(): ProviderModuleBlueprint;
|
|
417
|
+
private convertToModuleAndInjectIntoAppModuleIfGlobal;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
declare abstract class IProviderModule {
|
|
421
|
+
/** The `identifier` of this {@link IProviderModule | Module}. */
|
|
422
|
+
readonly id: ModuleIdentifier;
|
|
590
423
|
/**
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* **Note:** _All the {@link _onBind}, {@link _onGet}, {@link _onRebind} and {@link _onUnbind} registered callbacks will be removed_
|
|
424
|
+
* The {@link ModuleDefinition} of this {@link IProviderModule | Module}.
|
|
594
425
|
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
426
|
+
* **Note:** _You shouldn't manually modify the {@link ModuleDefinition}!_
|
|
427
|
+
* _Interact via the {@link update} methods instead._
|
|
597
428
|
*/
|
|
598
|
-
|
|
429
|
+
readonly definition: ModuleDefinition<true>;
|
|
430
|
+
/** The {@link IDynamicModuleDefinition} of this {@link IProviderModule | Module}. */
|
|
431
|
+
readonly update: IDynamicModuleDefinition;
|
|
432
|
+
/** The {@link IMiddlewaresManager} of this {@link IProviderModule | Module}. */
|
|
433
|
+
readonly middlewares: IMiddlewaresManager;
|
|
434
|
+
/** It'll be `true` after the {@link dispose} method has been invoked. */
|
|
435
|
+
readonly isDisposed: boolean;
|
|
599
436
|
/**
|
|
600
|
-
*
|
|
601
|
-
* with the one provided.
|
|
437
|
+
* Instantiates a new `instance` of the {@link IProviderModule} class.
|
|
602
438
|
*
|
|
603
|
-
*
|
|
604
|
-
*/
|
|
605
|
-
_overwriteContainer(cb: () => Container): void;
|
|
606
|
-
/**
|
|
607
|
-
* Binds a {@link ProviderToken | provider}.
|
|
439
|
+
* **Note:** _Check also the {@link blueprint} method._
|
|
608
440
|
*
|
|
609
|
-
*
|
|
441
|
+
* @param options The {@link ProviderModuleOptions}.
|
|
610
442
|
*/
|
|
611
|
-
|
|
443
|
+
static create(options: ProviderModuleOptions): IProviderModule;
|
|
612
444
|
/**
|
|
613
|
-
*
|
|
614
|
-
*
|
|
615
|
-
* otherwise an error is thrown.
|
|
445
|
+
* Can be used when you _don't_ want to initialize a `ProviderModule` eagerly as each `ProviderModule` has its own container
|
|
446
|
+
* initialized as soon as you do `ProviderModule.create({...})`.
|
|
616
447
|
*
|
|
617
|
-
*
|
|
618
|
-
*
|
|
619
|
-
* @returns Either the {@link T | dependency} or `undefined` if {@link GetOptions.optional} is set to `true`.
|
|
448
|
+
* The {@link ProviderModuleBlueprint} allows you to just _define_ a `blueprint` of a `ProviderModule`,
|
|
449
|
+
* you can then decide to either _instantiate_ it or _import_ as it is into different modules _(or blueprints)_.
|
|
620
450
|
*
|
|
621
|
-
*
|
|
622
|
-
|
|
623
|
-
__get<T>(provider: ProviderToken<T>, options?: GetOptions): T;
|
|
624
|
-
/**
|
|
625
|
-
* Resolves a dependency by its runtime identifier.
|
|
626
|
-
* The runtime identifier must be associated with only one binding,
|
|
627
|
-
* otherwise an error is thrown.
|
|
451
|
+
* **Note:** _As soon as you import a `blueprint` into a `module`, it'll be automatically transformed into a {@link IProviderModule} instance!_
|
|
452
|
+
* _Also keep in mind that editing the `blueprint` after it has been consumed by a `module` will not propagate the changes to the consumer `module`!_
|
|
628
453
|
*
|
|
629
|
-
*
|
|
630
|
-
*
|
|
631
|
-
*
|
|
454
|
+
* **[WARNING]**: When you import the same `blueprint` into different modules, each `module` will create a new `module` instance
|
|
455
|
+
* based on that specific `blueprint`, this may not seem obvious at first, but it happens because a `blueprint` is just that, a template defining the options
|
|
456
|
+
* which will be used to build a `module`.
|
|
457
|
+
* This means that if a `blueprint` exports a `singleton` provider, when imported into two separate modules, each `module` will have _its own_ instance of that
|
|
458
|
+
* specific `singleton` provider!
|
|
459
|
+
* You should also keep in mind that once a `blueprint` has been encapsulated into a `module`, it can't be removed anymore as you can do with the modules!
|
|
632
460
|
*
|
|
633
|
-
*
|
|
634
|
-
*/
|
|
635
|
-
__getAsync<T>(provider: ProviderToken<T>, options?: GetOptions): Promise<T>;
|
|
636
|
-
/** See {@link https://inversify.io/docs/api/container/#getall | Container.getAll} for more details. */
|
|
637
|
-
__getAll<T>(provider: ProviderToken<T>, options?: GetOptions): T[];
|
|
638
|
-
/** See {@link https://inversify.io/docs/api/container/#getallasync | Container.getAllAsync} for more details. */
|
|
639
|
-
__getAllAsync<T>(provider: ProviderToken<T>, options?: GetOptions): Promise<T[]>;
|
|
640
|
-
/**
|
|
641
|
-
* Can be used to check if there are registered bindings for the {@link provider | provider}.
|
|
461
|
+
* Why should you use a {@link ProviderModuleBlueprint}?
|
|
642
462
|
*
|
|
643
|
-
*
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
/**
|
|
647
|
-
* Can be useed to check if there are registered bindings for the {@link provider | provider} only in the current container.
|
|
463
|
+
* - To _define module configurations upfront_ without incurring the cost of immediate initialization.
|
|
464
|
+
* - To reuse module _definitions across_ different parts of your application while maintaining isolated instances.
|
|
465
|
+
* - To _compose modules flexibly_, allowing you to adjust module dependencies dynamically before instantiation.
|
|
648
466
|
*
|
|
649
|
-
*
|
|
650
|
-
*/
|
|
651
|
-
__isCurrentBound(provider: ProviderToken, options?: IsBoundOptions): boolean;
|
|
652
|
-
/**
|
|
653
|
-
* Save the state of the container to be later restored with the restore method.
|
|
467
|
+
* You can always edit a property of the `blueprint` after creating it by doing:
|
|
654
468
|
*
|
|
655
|
-
*
|
|
656
|
-
|
|
657
|
-
__takeSnapshot(): void;
|
|
658
|
-
/**
|
|
659
|
-
* Restore container state to last snapshot.
|
|
469
|
+
* ```ts
|
|
470
|
+
* const GarageModuleBlueprint = ProviderModule.blueprint({ id: 'GarageModuleBlueprint' });
|
|
660
471
|
*
|
|
661
|
-
*
|
|
662
|
-
*/
|
|
663
|
-
__restoreSnapshot(): void;
|
|
664
|
-
/**
|
|
665
|
-
* Convenience method that unbinds a {@link ProviderToken | provider} and then creates a new binding for it.
|
|
666
|
-
* This is equivalent to calling await `container.unbind` followed by `container.bind`, but in a single method.
|
|
472
|
+
* // Later in your code
|
|
667
473
|
*
|
|
668
|
-
*
|
|
669
|
-
* @returns A {@link BindToFluentSyntax | binding builder} to continue configuring the new binding.
|
|
474
|
+
* GarageModuleBlueprint.imports = [...GarageModuleBlueprint.imports, PorscheModule, FerrariModuleBlueprint];
|
|
670
475
|
*
|
|
671
|
-
*
|
|
672
|
-
*/
|
|
673
|
-
__rebind<T>(provider: ProviderToken<T>): Promise<BindToFluentSyntax<T>>;
|
|
674
|
-
/**
|
|
675
|
-
* Synchronous version of {@link __rebindProvider}. Unbinds a {@link ProviderToken | provider} synchronously and then creates a new binding for it.
|
|
676
|
-
* Will throw an error if the unbind operation would be asynchronous.
|
|
476
|
+
* // ...
|
|
677
477
|
*
|
|
678
|
-
*
|
|
679
|
-
* @returns A {@link BindToFluentSyntax | binding builder} to continue configuring the new binding.
|
|
478
|
+
* const GarageModule = ProviderModule.create(GarageModuleBlueprint);
|
|
680
479
|
*
|
|
681
|
-
*
|
|
682
|
-
*/
|
|
683
|
-
__rebindSync<T>(provider: ProviderToken<T>): BindToFluentSyntax<T>;
|
|
684
|
-
/**
|
|
685
|
-
* Removes **all** the associated bindings with the {@link provider} from the container.
|
|
480
|
+
* // or
|
|
686
481
|
*
|
|
687
|
-
*
|
|
482
|
+
* ExistingModule.update.addImport(GarageModuleBlueprint);
|
|
483
|
+
* ```
|
|
688
484
|
*
|
|
689
|
-
*
|
|
485
|
+
* @param moduleOptions The {@link ProviderModuleOptions}.
|
|
486
|
+
* @param blueprintOptions Options specific to the {@link ProviderModuleBlueprint | Blueprint} instance, see {@link ModuleBlueprintOptions}.
|
|
690
487
|
*/
|
|
691
|
-
|
|
488
|
+
static blueprint(moduleOptions: ProviderModuleOptions, blueprintOptions?: ModuleBlueprintOptions): ProviderModuleBlueprint;
|
|
692
489
|
/**
|
|
693
|
-
*
|
|
694
|
-
* This method works like {@link __unbind} but does not return a Promise.
|
|
695
|
-
* If the unbinding operation would be asynchronous (e.g. due to deactivation handlers),
|
|
696
|
-
* it will throw an error. Use this method when you know the operation won't involve async deactivations.
|
|
490
|
+
* Can be used to check if this {@link IProviderModule | Module} has a specific `module` imported into it.
|
|
697
491
|
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
700
|
-
* See {@link https://inversify.io/docs/api/container/#unbindsync | Container.unbindSync} for more details.
|
|
492
|
+
* @param idOrModule Either the {@link ModuleIdentifier} or the {@link IProviderModule} itself.
|
|
701
493
|
*/
|
|
702
|
-
|
|
494
|
+
isImportingModule(idOrModule: ModuleIdentifier | IProviderModule): boolean;
|
|
703
495
|
/**
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
* This will result in the {@link https://inversify.io/docs/fundamentals/lifecycle/deactivation/ | deactivation process}.
|
|
496
|
+
* Can be used to check if this {@link IProviderModule | Module} has a specific `provider` bound to _its_ container.
|
|
707
497
|
*
|
|
708
|
-
*
|
|
498
|
+
* @param provider The {@link DependencyProvider | Provider} to lookup for.
|
|
709
499
|
*/
|
|
710
|
-
|
|
711
|
-
}
|
|
712
|
-
type InternalInitOptions = Except<ProviderModuleOptions & ProviderModuleOptionsInternal, 'identifier' | 'isAppModule'>;
|
|
713
|
-
type RegisteredSideEffects = Map<ProviderToken, {
|
|
714
|
-
onBindEffects: OnBindEffects[];
|
|
715
|
-
onGetEffects: OnGetEffects[];
|
|
716
|
-
onRebindEffects: OnRebindEffects[];
|
|
717
|
-
onUnbindEffects: OnUnbindEffects[];
|
|
718
|
-
}>;
|
|
719
|
-
type OnBindEffects = () => Promise<void> | void;
|
|
720
|
-
type OnGetEffects = {
|
|
721
|
-
once: boolean;
|
|
722
|
-
invoked: boolean;
|
|
723
|
-
cb: () => Promise<void> | void;
|
|
724
|
-
};
|
|
725
|
-
type OnRebindEffects = () => Promise<void> | void;
|
|
726
|
-
type OnUnbindEffects = {
|
|
727
|
-
registerModuleId?: ModuleIdentifier;
|
|
728
|
-
cb: () => Promise<void> | void;
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
interface IProviderModule {
|
|
732
|
-
/** The module unique ID. */
|
|
733
|
-
readonly identifier: ModuleIdentifier;
|
|
734
|
-
/** See {@link ProviderModuleOptions.isGlobal}. */
|
|
735
|
-
readonly isGlobal: ProviderModuleOptions['isGlobal'];
|
|
736
|
-
readonly isDisposed: boolean;
|
|
500
|
+
hasProvider<T>(provider: DependencyProvider<T>): boolean;
|
|
737
501
|
/**
|
|
738
|
-
* Can be used to retrieve a
|
|
502
|
+
* Can be used to retrieve a {@link provider} from the module container.
|
|
739
503
|
*
|
|
740
504
|
* @param provider The {@link ProviderToken}.
|
|
741
|
-
* @param isOptional When set to `false` _(default)_ an exception will be thrown when the {@link
|
|
742
|
-
* @
|
|
505
|
+
* @param isOptional When set to `false` _(default)_ an exception will be thrown when the supplied {@link ProviderToken} isn't bound.
|
|
506
|
+
* @param asList Set to `true` if you need to retrieve _all_ the bound identifiers of the supplied {@link ProviderToken}. _(defaults to `false`)_
|
|
743
507
|
*/
|
|
744
|
-
get<T>(provider: ProviderToken<T>, isOptional?:
|
|
508
|
+
get<T, IsOptional extends boolean | undefined = undefined, AsList extends boolean | undefined = undefined>(provider: ProviderToken<T>, isOptional?: IsOptional, asList?: AsList): ProviderModuleGetReturn<T, IsOptional, AsList>;
|
|
745
509
|
/**
|
|
746
|
-
* Can be used to retrieve many
|
|
510
|
+
* Can be used to retrieve many providers from the module container at once.
|
|
747
511
|
*
|
|
748
512
|
* @param deps Either one or more {@link ProviderToken}.
|
|
749
|
-
* @returns Tuple containing the {@link D |
|
|
513
|
+
* @returns Tuple containing the {@link D | providers}.
|
|
750
514
|
*
|
|
751
|
-
* @example
|
|
752
515
|
* ```ts
|
|
753
516
|
* // When ProviderTokens are supplied, TS auto-inference works as expected.
|
|
754
517
|
* // `car` will infer the `Car` type, `engine` the `Engine` type and `dashboard` the `Dashboard` type.
|
|
755
|
-
* const [car, engine, dashboard] =
|
|
518
|
+
* const [car, engine, dashboard, wheels] = Module.getMany(
|
|
756
519
|
* Car,
|
|
757
520
|
* Engine,
|
|
758
|
-
* { provider: Dashboard, isOptional: true }
|
|
521
|
+
* { provider: Dashboard, isOptional: true },
|
|
522
|
+
* { provider: Wheel, asList: true },
|
|
759
523
|
* );
|
|
760
524
|
*
|
|
761
525
|
* // When auto-inference is not possible, you can manually cast the types.
|
|
762
|
-
* const [configService, userService] =
|
|
526
|
+
* const [configService, userService] = Module.getMany('CONFIG_SERVICE', UserService) as [ConfigService, UserService];
|
|
763
527
|
* // Now the `configService` is of type `ConfigService` and the `userService` is of type `UserService`.
|
|
764
528
|
* ```
|
|
765
529
|
*/
|
|
766
|
-
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D
|
|
530
|
+
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken | ProviderIdentifier)[]>(...deps: D): ProviderModuleGetManyReturn<D>;
|
|
767
531
|
/**
|
|
768
|
-
* Can be used to
|
|
532
|
+
* Can be used to check if _this_ {@link IProviderModule | Module} is `exporting` a specific {@link IProviderModule | Module}.
|
|
769
533
|
*
|
|
770
|
-
* @param
|
|
534
|
+
* @param idOrModule Either the {@link ModuleIdentifier} or the {@link IProviderModule} itself.
|
|
771
535
|
*/
|
|
772
|
-
|
|
536
|
+
isExportingModule(idOrModule: ModuleIdentifier | IProviderModule): boolean;
|
|
773
537
|
/**
|
|
774
|
-
*
|
|
538
|
+
* Can be used to check if _this_ {@link IProviderModule | Module} is `exporting` a specific {@link DependencyProvider | Provider}.
|
|
775
539
|
*
|
|
776
|
-
*
|
|
540
|
+
* @param tokenOrIdentifier Either the {@link ProviderToken} or the {@link ProviderIdentifier} itself.
|
|
777
541
|
*/
|
|
778
|
-
|
|
542
|
+
isExportingProvider(tokenOrIdentifier: ProviderToken | ProviderIdentifier): boolean;
|
|
779
543
|
/**
|
|
780
|
-
*
|
|
544
|
+
* Can be used to _completely_ reset a module.
|
|
781
545
|
*
|
|
782
|
-
*
|
|
546
|
+
* It means that all bound providers will be removed from the `container` and
|
|
547
|
+
* all definitions cleared, leaving it as a pristine module ready to be
|
|
548
|
+
* updated with new definitions.
|
|
549
|
+
*
|
|
550
|
+
* **Note:** _This is not the same as the {@link dispose} method!_
|
|
551
|
+
*/
|
|
552
|
+
reset(): Promise<void>;
|
|
553
|
+
/**
|
|
554
|
+
* It first invokes the {@link reset} method and then permanentely destroys the module's `container`.
|
|
555
|
+
*
|
|
556
|
+
* **Note:** _If other modules have imported `this` module, they'll not be able anymore to_
|
|
557
|
+
* _resolve dependencies from it which will cause errors to be thrown!_
|
|
558
|
+
* _Make sure to use {@link dispose} carefully as it is an irreversible action._
|
|
783
559
|
*/
|
|
784
560
|
dispose(): Promise<void>;
|
|
785
|
-
/** Returns the {@link IProviderModule.
|
|
561
|
+
/** Returns the {@link IProviderModule.id}. */
|
|
786
562
|
toString(): string;
|
|
787
563
|
}
|
|
788
|
-
type
|
|
789
|
-
type
|
|
790
|
-
|
|
791
|
-
[K in keyof Tokens]: Tokens[K] extends ProviderModuleGetManyParam<infer U> ? U : Tokens[K] extends ProviderToken<infer T> ? T : Tokens[K] extends ProviderIdentifier<infer I> ? I : never;
|
|
564
|
+
type ProviderModuleGetReturn<T, IsOptional extends boolean | undefined = undefined, AsList extends boolean | undefined = undefined> = AsList extends true ? IsOptional extends true ? (T | undefined)[] : T[] : IsOptional extends true ? T | undefined : T;
|
|
565
|
+
type ProviderModuleGetManyReturn<Tokens extends (ProviderModuleGetManyParam<any> | ProviderToken | ProviderIdentifier)[]> = {
|
|
566
|
+
[K in keyof Tokens]: Tokens[K] extends ProviderModuleGetManyParam<infer U> ? ProviderModuleGetReturn<U, Tokens[K]['isOptional'], Tokens[K]['asList']> : Tokens[K] extends ProviderToken<infer T> ? T : Tokens[K] extends ProviderIdentifier<infer I> ? I : never;
|
|
792
567
|
};
|
|
793
568
|
type ProviderModuleGetManyParam<T> = {
|
|
794
569
|
/** The {@link ProviderToken}. */
|
|
795
570
|
provider: ProviderToken<T>;
|
|
796
571
|
/** When set to `false` _(default)_ an exception will be thrown when the {@link ProviderModuleGetManyParam.provider | provider} isn't bound. */
|
|
797
572
|
isOptional?: boolean;
|
|
573
|
+
/** Set to `true` if you need to retrieve _all_ the bound identifiers of the supplied {@link ProviderToken}. _(defaults to `false`)_ */
|
|
574
|
+
asList?: boolean;
|
|
798
575
|
};
|
|
799
576
|
|
|
800
|
-
interface
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
577
|
+
interface ProviderModuleOptions {
|
|
578
|
+
/**
|
|
579
|
+
* The module `ID`.
|
|
580
|
+
*
|
|
581
|
+
* **Note:** _It doesn't have to be unique, however, the `AppModule` id is a reserved id and it'll throw an error if used._
|
|
582
|
+
*/
|
|
583
|
+
readonly id: ModuleIdentifier;
|
|
584
|
+
/** Import additional `modules` or `blueprints` into _this_ module. */
|
|
585
|
+
readonly imports?: ImportsDefinition;
|
|
586
|
+
/** The `providers` that will be instantiated by the container and that may be shared at least across _this_ module. */
|
|
587
|
+
readonly providers?: ProvidersDefinition;
|
|
588
|
+
/**
|
|
589
|
+
* The subset of `providers`, `modules` or `blueprints` that
|
|
590
|
+
* are provided by _this_ module and should be available in other modules which import _this_ module.
|
|
591
|
+
*/
|
|
592
|
+
readonly exports?: ExportsDefinition;
|
|
807
593
|
/**
|
|
808
|
-
*
|
|
809
|
-
* which _can help_ in avoiding common pitfalls which may otherwise produce
|
|
810
|
-
* undesired side-effects or edge-case bugs.
|
|
594
|
+
* The default {@link InjectionScope} to be used when a {@link ProvidersDefinition | Provider} does not have a defined `scope`.
|
|
811
595
|
*
|
|
812
|
-
*
|
|
596
|
+
* Defaults to {@link InjectionScope.Singleton}.
|
|
597
|
+
*/
|
|
598
|
+
readonly defaultScope?: InjectionScope;
|
|
599
|
+
/**
|
|
600
|
+
* When a module is set to be `global`, it'll be automatically imported into the `AppModule`
|
|
601
|
+
* during its initialization.
|
|
813
602
|
*
|
|
814
|
-
*
|
|
603
|
+
* **Note:** _Importing a `global` module into another module does nothing._
|
|
815
604
|
*
|
|
816
|
-
* Defaults to `
|
|
605
|
+
* Defaults to `false`.
|
|
817
606
|
*/
|
|
818
|
-
|
|
607
|
+
readonly isGlobal?: boolean;
|
|
608
|
+
/**
|
|
609
|
+
* Callback which will be invoked once the module container has been initialized
|
|
610
|
+
* and the providers resolved.
|
|
611
|
+
*
|
|
612
|
+
* @param module The instance of the {@link IProviderModule | module}.
|
|
613
|
+
*/
|
|
614
|
+
readonly onReady?: (module: IProviderModule) => void | Promise<void>;
|
|
615
|
+
/**
|
|
616
|
+
* The provided callbacks will be invoked when the `reset` method is invoked.
|
|
617
|
+
*
|
|
618
|
+
* @returns See {@link OnCleanupOptions}.
|
|
619
|
+
*/
|
|
620
|
+
readonly onReset?: () => OnCleanupOptions;
|
|
621
|
+
/**
|
|
622
|
+
* The provided callbacks will be invoked when the `dispose` method is invoked.
|
|
623
|
+
*
|
|
624
|
+
* @returns See {@link OnCleanupOptions}.
|
|
625
|
+
*/
|
|
626
|
+
readonly onDispose?: () => OnCleanupOptions;
|
|
627
|
+
}
|
|
628
|
+
type OnCleanupOptions = RequireAtLeastOne<{
|
|
629
|
+
/**
|
|
630
|
+
* It'll be invoked _before_ the process starts.
|
|
631
|
+
*
|
|
632
|
+
* @param module The {@link IProviderModule | module} instance.
|
|
633
|
+
*/
|
|
634
|
+
before: (module: IProviderModule) => void | Promise<void>;
|
|
635
|
+
/** It'll be invoked _after_ the process ended. */
|
|
636
|
+
after: () => void | Promise<void>;
|
|
637
|
+
}>;
|
|
638
|
+
|
|
639
|
+
interface ProviderModuleOptionsInternal extends ProviderModuleOptions {
|
|
640
|
+
/** Overwrite the internal reference to the `AppModule`. */
|
|
641
|
+
appModuleRef?: IProviderModule;
|
|
642
|
+
inversify?: {
|
|
643
|
+
/** Overwrite the `Inversify` parent container. */
|
|
644
|
+
parentContainer?: Container;
|
|
645
|
+
};
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
declare class ProviderModule implements IProviderModule {
|
|
649
|
+
get id(): ModuleIdentifier;
|
|
650
|
+
get definition(): ModuleDefinition<true>;
|
|
651
|
+
get update(): IDynamicModuleDefinition;
|
|
652
|
+
get middlewares(): IMiddlewaresManager;
|
|
653
|
+
get isDisposed(): boolean;
|
|
654
|
+
get isAppModule(): boolean;
|
|
655
|
+
/**
|
|
656
|
+
* Holds a reference to the `AppModule`.
|
|
657
|
+
*
|
|
658
|
+
* Static property needed in order to avoid introducing a _cirular dependency_ between
|
|
659
|
+
* the `AppModule` instance and the `ProviderModule` class.
|
|
660
|
+
*/
|
|
661
|
+
static readonly APP_MODULE_REF: IProviderModule;
|
|
662
|
+
readonly appModuleRef: ProviderModule;
|
|
663
|
+
readonly options: ProviderModuleOptions;
|
|
664
|
+
readonly middlewaresManager: MiddlewaresManager;
|
|
665
|
+
readonly dynamicModuleDef: DynamicModuleDefinition;
|
|
666
|
+
readonly moduleContainer: ModuleContainer;
|
|
667
|
+
readonly importedModuleContainers: Map<IProviderModule, ImportedModuleContainer>;
|
|
668
|
+
private disposed;
|
|
669
|
+
constructor({ appModuleRef: appModule, inversify, ...publicOptions }: ProviderModuleOptionsInternal);
|
|
670
|
+
static create(optionsOrBlueprint: ProviderModuleOptions | ProviderModuleBlueprint): IProviderModule;
|
|
671
|
+
static blueprint(moduleOptions: ProviderModuleOptions, blueprintOptions?: ModuleBlueprintOptions): ProviderModuleBlueprint;
|
|
672
|
+
isImportingModule(idOrModule: ModuleIdentifier | IProviderModule): boolean;
|
|
673
|
+
hasProvider<T>(provider: ProviderToken<T>): boolean;
|
|
674
|
+
get<T, IsOptional extends boolean | undefined = undefined, AsList extends boolean | undefined = undefined>(provider: ProviderToken<T>, isOptional?: IsOptional, asList?: AsList): ProviderModuleGetReturn<T, IsOptional, AsList>;
|
|
675
|
+
getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManyReturn<D>;
|
|
676
|
+
isExportingModule(idOrModule: ModuleIdentifier | IProviderModule): boolean;
|
|
677
|
+
isExportingProvider(tokenOrIdentifier: ProviderToken | ProviderIdentifier): boolean;
|
|
678
|
+
reset(shouldInvokeCb?: boolean): Promise<void>;
|
|
679
|
+
dispose(): Promise<void>;
|
|
680
|
+
toString(): string;
|
|
681
|
+
private throwIfIdIsMissing;
|
|
682
|
+
private throwIfDisposed;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* The `root` {@link IProviderModule} of your application.
|
|
687
|
+
*
|
|
688
|
+
* All global modules are imported into the {@link AppModule} and all your custom
|
|
689
|
+
* modules inherit from it.
|
|
690
|
+
*/
|
|
691
|
+
declare const AppModule: IProviderModule;
|
|
692
|
+
|
|
693
|
+
type ModuleIdentifier = symbol | string;
|
|
694
|
+
type ModuleOrBlueprint = (ProviderModule | IProviderModule) | ProviderModuleBlueprint;
|
|
695
|
+
type ImportsDefinition = ModuleOrBlueprint[];
|
|
696
|
+
type ProvidersDefinition = DependencyProvider[];
|
|
697
|
+
type ExportsDefinition = ExportDefinition[];
|
|
698
|
+
type ImportsDefinitionOptimized = Set<IProviderModule>;
|
|
699
|
+
type ProvidersDefinitionOptimized = Set<DependencyProvider>;
|
|
700
|
+
type ExportsDefinitionOptimized = Set<ExportDefinition>;
|
|
701
|
+
interface ModuleDefinition<Optimized extends boolean = false> {
|
|
702
|
+
readonly imports: Optimized extends false ? ImportsDefinition : ImportsDefinitionOptimized;
|
|
703
|
+
readonly providers: Optimized extends false ? ProvidersDefinition : ProvidersDefinitionOptimized;
|
|
704
|
+
readonly exports: Optimized extends false ? ExportsDefinition : ExportsDefinitionOptimized;
|
|
819
705
|
}
|
|
706
|
+
type ExportDefinition = ProviderToken | ModuleOrBlueprint;
|
|
820
707
|
|
|
821
708
|
/** See {@link https://inversify.io/docs/api/decorator/#inject} for more details. */
|
|
822
709
|
declare function Inject(provider: ProviderToken): MethodDecorator & ParameterDecorator & PropertyDecorator;
|
|
@@ -847,25 +734,31 @@ declare class InjectionError extends Error {
|
|
|
847
734
|
/** Exception which indicates that there is a generic error with an instance of {@link IProviderModule}. */
|
|
848
735
|
declare class InjectionProviderModuleError extends Error {
|
|
849
736
|
name: string;
|
|
850
|
-
constructor(module:
|
|
737
|
+
constructor(module: IProviderModule, message: string);
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/** Exception which indicates that an `unknown` type of {@link ProviderToken} has been supplied. */
|
|
741
|
+
declare class InjectionProviderModuleUnknownProviderError extends InjectionProviderModuleError {
|
|
742
|
+
name: string;
|
|
743
|
+
constructor(module: IProviderModule, providerToken: ProviderToken);
|
|
851
744
|
}
|
|
852
745
|
|
|
853
746
|
/** Exception which indicates an invokation of a disposed module. */
|
|
854
747
|
declare class InjectionProviderModuleDisposedError extends InjectionProviderModuleError {
|
|
855
748
|
name: string;
|
|
856
|
-
constructor(module:
|
|
749
|
+
constructor(module: IProviderModule);
|
|
857
750
|
}
|
|
858
751
|
|
|
859
752
|
/** Exception which indicates that a module has been initialized without an `identifier`. */
|
|
860
753
|
declare class InjectionProviderModuleMissingIdentifierError extends InjectionProviderModuleError {
|
|
861
754
|
name: string;
|
|
862
|
-
constructor(module:
|
|
755
|
+
constructor(module: IProviderModule);
|
|
863
756
|
}
|
|
864
757
|
|
|
865
|
-
/** Exception which indicates
|
|
866
|
-
declare class
|
|
758
|
+
/** Exception which indicates that a module container does not contain the requested provider. */
|
|
759
|
+
declare class InjectionProviderModuleMissingProviderError extends InjectionProviderModuleError {
|
|
867
760
|
name: string;
|
|
868
|
-
constructor(module:
|
|
761
|
+
constructor(module: IProviderModule, providerToken: ProviderToken);
|
|
869
762
|
}
|
|
870
763
|
|
|
871
764
|
declare function injectionScopeToBindingScope(injectionScope: InjectionScope): BindingScope;
|
|
@@ -876,9 +769,11 @@ declare namespace ProviderTokenHelpers {
|
|
|
876
769
|
function isValueToken<T>(provider: ProviderToken<T>): provider is ProviderValueToken<T>;
|
|
877
770
|
function isFactoryToken<T>(provider: ProviderToken<T>): provider is ProviderFactoryToken<T>;
|
|
878
771
|
function isProviderIdentifier<T = any>(value: any): value is ProviderIdentifier<T>;
|
|
879
|
-
function
|
|
880
|
-
function
|
|
881
|
-
function
|
|
772
|
+
function toProviderIdentifier<T = any>(provider: ProviderToken<T>): ProviderIdentifier<T>;
|
|
773
|
+
function toProviderIdentifiers(providers: ProviderToken[]): ProviderIdentifier<unknown>[];
|
|
774
|
+
function providerIdentifierToString(providerIdentifier: ProviderIdentifier): string;
|
|
775
|
+
function providerTokenToString(providerToken: ProviderToken): string;
|
|
776
|
+
function providerTokensAreEqual(p0: ProviderToken, p1: ProviderToken): boolean;
|
|
882
777
|
/**
|
|
883
778
|
* The priority order is as follows:
|
|
884
779
|
* 1. From the `ProviderToken.scope`
|
|
@@ -895,14 +790,11 @@ declare namespace ProviderTokenHelpers {
|
|
|
895
790
|
}
|
|
896
791
|
|
|
897
792
|
declare namespace ProviderModuleHelpers {
|
|
898
|
-
function
|
|
899
|
-
function
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
function isModuleDefinition(value: any): value is IProviderModuleDefinition;
|
|
904
|
-
function isLazyExport(exp: any): exp is LazyExport;
|
|
905
|
-
function tryStaticOrLazyExportToStaticExport(module: IProviderModule, exp: StaticExport | LazyExport): StaticExport | void;
|
|
793
|
+
function isModule(value: any): value is IProviderModule;
|
|
794
|
+
function isBlueprint(value: any): value is ProviderModuleBlueprint;
|
|
795
|
+
function isModuleOrBlueprint(value: any): value is IProviderModule | ProviderModuleBlueprint;
|
|
796
|
+
function tryBlueprintToModule(value: IProviderModule | ProviderModuleBlueprint): IProviderModule;
|
|
797
|
+
function blueprintToModule(moduleBlueprint: ProviderModuleBlueprint): IProviderModule;
|
|
906
798
|
}
|
|
907
799
|
|
|
908
800
|
declare function isPlainObject(o: any): o is object;
|
|
@@ -913,4 +805,6 @@ declare function isFunction(v: any): boolean;
|
|
|
913
805
|
|
|
914
806
|
declare function isClassOrFunction(value: any): value is Function | Class<any>;
|
|
915
807
|
|
|
916
|
-
|
|
808
|
+
declare function deepClone<T>(obj: T): T;
|
|
809
|
+
|
|
810
|
+
export { AppModule, DefinitionEventType, type DependencyProvider, type ExportDefinition, type ExportsDefinition, type ExportsDefinitionOptimized, IProviderModule, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleMissingIdentifierError, InjectionProviderModuleMissingProviderError, InjectionProviderModuleUnknownProviderError, InjectionScope, MiddlewareType, MultiInject, Named, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, ProviderModuleBlueprint, type ProviderModuleGetManyParam, type ProviderModuleGetManyReturn, type ProviderModuleGetReturn, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, Tagged, Unmanaged, bindingScopeToInjectionScope, deepClone, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
|