@adimm/x-injection 0.3.2 → 0.4.0
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 +13 -5
- package/dist/index.cjs +150 -134
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +38 -9
- package/dist/index.d.ts +38 -9
- package/dist/index.js +141 -125
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ xInjection <a href="https://www.npmjs.com/package/@adimm/x-injection" targe
|
|
|
26
26
|
- [Dynamic Exports](#dynamic-exports)
|
|
27
27
|
- [Advanced Usage](#advanced-usage)
|
|
28
28
|
- [Documentation](#documentation)
|
|
29
|
+
- [ReactJS Implementation](#reactjs-implementation)
|
|
29
30
|
- [Contributing](#contributing)
|
|
30
31
|
|
|
31
32
|
## Overview
|
|
@@ -126,6 +127,7 @@ The below list shows them in order of priority _(highest to lowest)_, meaning th
|
|
|
126
127
|
3. By providing the [defaultScope](https://adimarianmutu.github.io/x-injection/interfaces/ProviderModuleOptions.html#defaultscope) property when initializing a `ProviderModule`:
|
|
127
128
|
```ts
|
|
128
129
|
const RainModule = new ProviderModule({
|
|
130
|
+
identifier: Symbol('RainModule'),
|
|
129
131
|
defaultScope: InjectionScope.Transient,
|
|
130
132
|
});
|
|
131
133
|
```
|
|
@@ -152,7 +154,7 @@ export class SessionService {
|
|
|
152
154
|
}
|
|
153
155
|
|
|
154
156
|
export const DatabaseModule = new ProviderModule({
|
|
155
|
-
|
|
157
|
+
identifier: Symbol('DatabaseModule'),
|
|
156
158
|
providers: [DatabaseService],
|
|
157
159
|
exports: [DatabaseService],
|
|
158
160
|
onReady: async (module) => {
|
|
@@ -168,7 +170,7 @@ export const DatabaseModule = new ProviderModule({
|
|
|
168
170
|
});
|
|
169
171
|
|
|
170
172
|
export const SessionModule = new ProviderModule({
|
|
171
|
-
|
|
173
|
+
identifier: Symbol('SessionModule'),
|
|
172
174
|
defaultScope: InjectionScope.Request,
|
|
173
175
|
providers: [SessionService],
|
|
174
176
|
exports: [SessionService],
|
|
@@ -244,7 +246,7 @@ class CrowService extends AnimalService {
|
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
const AnimalModule = new ProviderModule({
|
|
247
|
-
|
|
249
|
+
identifier: Symbol('AnimalModule'),
|
|
248
250
|
providers: [AnimalService, { provide: WingsService, useClass: WingsService, scope: InjectionScope.Transient }],
|
|
249
251
|
exports: [AnimalService, WingsService],
|
|
250
252
|
dynamicExports: (importerModule, moduleExports) => {
|
|
@@ -260,14 +262,14 @@ const AnimalModule = new ProviderModule({
|
|
|
260
262
|
});
|
|
261
263
|
|
|
262
264
|
const CrowModule = new ProviderModule({
|
|
263
|
-
|
|
265
|
+
identifier: Symbol('CrowModule'),
|
|
264
266
|
imports: [AnimalModule],
|
|
265
267
|
providers: [CrowService],
|
|
266
268
|
exports: [CrowService],
|
|
267
269
|
});
|
|
268
270
|
|
|
269
271
|
const CatModule = new ProviderModule({
|
|
270
|
-
|
|
272
|
+
identifier: Symbol('CatModule'),
|
|
271
273
|
imports: [AnimalModule],
|
|
272
274
|
providers: [CatService],
|
|
273
275
|
exports: [CatService],
|
|
@@ -308,6 +310,12 @@ Comprehensive, auto-generated documentation is available at:
|
|
|
308
310
|
|
|
309
311
|
👉 [https://adimarianmutu.github.io/x-injection/index.html](https://adimarianmutu.github.io/x-injection/index.html)
|
|
310
312
|
|
|
313
|
+
## ReactJS Implementation
|
|
314
|
+
|
|
315
|
+
You want to use it within a [ReactJS](https://react.dev/) project? Don't worry, the library does already have an official implementation for React ⚛️
|
|
316
|
+
|
|
317
|
+
For more details check out the [GitHub Repository](https://github.com/AdiMarianMutu/x-injection-reactjs).
|
|
318
|
+
|
|
311
319
|
## Contributing
|
|
312
320
|
|
|
313
321
|
Pull requests are warmly welcomed! 😃
|
package/dist/index.cjs
CHANGED
|
@@ -11,33 +11,33 @@ var e, i = Object.defineProperty, t = Object.getOwnPropertyDescriptor, n = Objec
|
|
|
11
11
|
enumerable: !0
|
|
12
12
|
});
|
|
13
13
|
})(s, {
|
|
14
|
-
ANONYMOUS_MODULE_DEFAULT_ID: () => c,
|
|
15
14
|
AppModule: () => H,
|
|
16
15
|
GLOBAL_APP_MODULE_ID: () => d,
|
|
17
16
|
GlobalAppModule: () => z,
|
|
18
|
-
GlobalContainer: () =>
|
|
19
|
-
Inject: () =>
|
|
20
|
-
InjectFromBase: () =>
|
|
21
|
-
Injectable: () =>
|
|
22
|
-
InjectionScope: () =>
|
|
23
|
-
MultiInject: () =>
|
|
24
|
-
Named: () =>
|
|
25
|
-
Optional: () =>
|
|
26
|
-
PostConstruct: () =>
|
|
27
|
-
PreDestroy: () =>
|
|
17
|
+
GlobalContainer: () => X,
|
|
18
|
+
Inject: () => b,
|
|
19
|
+
InjectFromBase: () => B,
|
|
20
|
+
Injectable: () => I,
|
|
21
|
+
InjectionScope: () => a,
|
|
22
|
+
MultiInject: () => T,
|
|
23
|
+
Named: () => D,
|
|
24
|
+
Optional: () => P,
|
|
25
|
+
PostConstruct: () => C,
|
|
26
|
+
PreDestroy: () => x,
|
|
28
27
|
ProviderModule: () => $,
|
|
29
|
-
ProviderModuleHelpers: () =>
|
|
30
|
-
ProviderTokenHelpers: () =>
|
|
31
|
-
Tagged: () =>
|
|
32
|
-
Unmanaged: () =>
|
|
33
|
-
XInjectionDynamicExportsOutOfRange: () =>
|
|
34
|
-
XInjectionError: () =>
|
|
35
|
-
XInjectionProviderModuleDisposedError: () =>
|
|
36
|
-
XInjectionProviderModuleError: () =>
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
ProviderModuleHelpers: () => f,
|
|
29
|
+
ProviderTokenHelpers: () => l,
|
|
30
|
+
Tagged: () => O,
|
|
31
|
+
Unmanaged: () => q,
|
|
32
|
+
XInjectionDynamicExportsOutOfRange: () => G,
|
|
33
|
+
XInjectionError: () => F,
|
|
34
|
+
XInjectionProviderModuleDisposedError: () => U,
|
|
35
|
+
XInjectionProviderModuleError: () => N,
|
|
36
|
+
XInjectionProviderModuleMissingIdentifierError: () => V,
|
|
37
|
+
bindingScopeToInjectionScope: () => h,
|
|
38
|
+
injectionScopeToBindingScope: () => u,
|
|
39
|
+
isClass: () => g,
|
|
40
|
+
isClassOrFunction: () => S,
|
|
41
41
|
isPlainObject: () => y
|
|
42
42
|
}), module.exports = (e = s, ((e, o, s, d) => {
|
|
43
43
|
if (o && "object" == typeof o || "function" == typeof o) for (let c of n(o)) r.call(e, c) || c === s || i(e, c, {
|
|
@@ -49,66 +49,66 @@ var e, i = Object.defineProperty, t = Object.getOwnPropertyDescriptor, n = Objec
|
|
|
49
49
|
value: !0
|
|
50
50
|
}), e));
|
|
51
51
|
|
|
52
|
-
var d = "GlobalAppModule", c =
|
|
52
|
+
var d = "GlobalAppModule", c = require("inversify"), a = function(e) {
|
|
53
53
|
return e[e.Singleton = 0] = "Singleton", e[e.Transient = 1] = "Transient", e[e.Request = 2] = "Request",
|
|
54
54
|
e;
|
|
55
55
|
}({});
|
|
56
56
|
|
|
57
|
-
function
|
|
57
|
+
function u(e) {
|
|
58
58
|
switch (e) {
|
|
59
|
-
case
|
|
59
|
+
case a.Singleton:
|
|
60
60
|
return "Singleton";
|
|
61
61
|
|
|
62
|
-
case
|
|
62
|
+
case a.Transient:
|
|
63
63
|
return "Transient";
|
|
64
64
|
|
|
65
|
-
case
|
|
65
|
+
case a.Request:
|
|
66
66
|
return "Request";
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
function
|
|
70
|
+
function h(e) {
|
|
71
71
|
switch (e) {
|
|
72
72
|
case "Singleton":
|
|
73
|
-
return
|
|
73
|
+
return a.Singleton;
|
|
74
74
|
|
|
75
75
|
case "Transient":
|
|
76
|
-
return
|
|
76
|
+
return a.Transient;
|
|
77
77
|
|
|
78
78
|
case "Request":
|
|
79
|
-
return
|
|
79
|
+
return a.Request;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
o(
|
|
83
|
+
o(u, "injectionScopeToBindingScope"), o(h, "bindingScopeToInjectionScope");
|
|
84
84
|
|
|
85
|
-
var f, p
|
|
85
|
+
var l, f, p = require("@inversifyjs/core");
|
|
86
86
|
|
|
87
|
-
function
|
|
87
|
+
function g(e) {
|
|
88
88
|
return "function" == typeof e && /^class\s/.test(Function.prototype.toString.call(e));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
function
|
|
91
|
+
function v(e) {
|
|
92
92
|
return "[object Object]" === Object.prototype.toString.call(e);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function y(e) {
|
|
96
|
-
if (!1 ===
|
|
96
|
+
if (!1 === v(e)) return !1;
|
|
97
97
|
const i = e.constructor;
|
|
98
98
|
if (void 0 === i) return !0;
|
|
99
99
|
const t = i.prototype;
|
|
100
|
-
return !1 !==
|
|
100
|
+
return !1 !== v(t) && !1 !== t.hasOwnProperty("isPrototypeOf");
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
function
|
|
103
|
+
function S(e) {
|
|
104
104
|
return "function" == typeof e;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
function
|
|
108
|
-
return void 0 === e ? (0,
|
|
107
|
+
function I(e) {
|
|
108
|
+
return void 0 === e ? (0, c.injectable)() : (0, c.injectable)(u(e));
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
o(
|
|
111
|
+
o(g, "isClass"), o(v, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
112
112
|
function i(e) {
|
|
113
113
|
return f(e) && "useClass" in e;
|
|
114
114
|
}
|
|
@@ -119,7 +119,7 @@ o(v, "isClass"), o(S, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
|
119
119
|
return f(e) && "useFactory" in e;
|
|
120
120
|
}
|
|
121
121
|
function r(e) {
|
|
122
|
-
return "string" == typeof e || "symbol" == typeof e ||
|
|
122
|
+
return "string" == typeof e || "symbol" == typeof e || g(e) || "function" == typeof e;
|
|
123
123
|
}
|
|
124
124
|
function s(e) {
|
|
125
125
|
return r(e) ? e : e.provide;
|
|
@@ -128,7 +128,7 @@ o(v, "isClass"), o(S, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
|
128
128
|
return e.map((e => s(e)));
|
|
129
129
|
}
|
|
130
130
|
function c(e, i) {
|
|
131
|
-
return u(e) ??
|
|
131
|
+
return u(e) ?? l(e) ?? i;
|
|
132
132
|
}
|
|
133
133
|
function a(e) {
|
|
134
134
|
if (f(e)) return e;
|
|
@@ -137,11 +137,11 @@ o(v, "isClass"), o(S, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
|
137
137
|
const i = a(e);
|
|
138
138
|
if (i) return i.scope;
|
|
139
139
|
}
|
|
140
|
-
function
|
|
140
|
+
function l(e) {
|
|
141
141
|
const i = s(e);
|
|
142
|
-
if (!
|
|
143
|
-
const t = (0,
|
|
144
|
-
return t ?
|
|
142
|
+
if (!g(i)) return;
|
|
143
|
+
const t = (0, p.getClassMetadata)(i)?.scope;
|
|
144
|
+
return t ? h(t) : void 0;
|
|
145
145
|
}
|
|
146
146
|
function f(e) {
|
|
147
147
|
return y(e) && "object" == typeof e && "provide" in e;
|
|
@@ -151,9 +151,9 @@ o(v, "isClass"), o(S, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
|
151
151
|
o(s, "toServiceIdentifier"), e.toServiceIdentifier = s, o(d, "toServiceIdentifiers"),
|
|
152
152
|
e.toServiceIdentifiers = d, o(c, "getInjectionScopeByPriority"), e.getInjectionScopeByPriority = c,
|
|
153
153
|
o(a, "tryGetProviderOptions"), e.tryGetProviderOptions = a, o(u, "tryGetScopeFromProvider"),
|
|
154
|
-
e.tryGetScopeFromProvider = u, o(
|
|
154
|
+
e.tryGetScopeFromProvider = u, o(l, "tryGetDecoratorScopeFromClass"), e.tryGetDecoratorScopeFromClass = l,
|
|
155
155
|
o(f, "hasProvideProperty");
|
|
156
|
-
}(
|
|
156
|
+
}(l || (l = {})), function(e) {
|
|
157
157
|
function i(e) {
|
|
158
158
|
return e;
|
|
159
159
|
}
|
|
@@ -162,86 +162,86 @@ o(v, "isClass"), o(S, "isObject"), o(y, "isPlainObject"), function(e) {
|
|
|
162
162
|
}
|
|
163
163
|
o(i, "buildInternalConstructorParams"), e.buildInternalConstructorParams = i, o(t, "isDynamicExport"),
|
|
164
164
|
e.isDynamicExport = t;
|
|
165
|
-
}(
|
|
165
|
+
}(f || (f = {})), o(S, "isClassOrFunction"), o(I, "Injectable");
|
|
166
166
|
|
|
167
|
-
var
|
|
167
|
+
var m = require("inversify");
|
|
168
168
|
|
|
169
|
-
function
|
|
170
|
-
return (0,
|
|
169
|
+
function b(e) {
|
|
170
|
+
return (0, m.inject)(l.toServiceIdentifier(e));
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
o(
|
|
173
|
+
o(b, "Inject");
|
|
174
174
|
|
|
175
|
-
var
|
|
175
|
+
var E = require("inversify");
|
|
176
176
|
|
|
177
|
-
function
|
|
178
|
-
return (0,
|
|
177
|
+
function T(e) {
|
|
178
|
+
return (0, E.multiInject)(l.toServiceIdentifier(e));
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
o(
|
|
181
|
+
o(T, "MultiInject");
|
|
182
182
|
|
|
183
|
-
var
|
|
183
|
+
var _ = require("inversify");
|
|
184
184
|
|
|
185
|
-
function
|
|
186
|
-
return (0,
|
|
185
|
+
function B(e) {
|
|
186
|
+
return (0, _.injectFromBase)(e);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
o(
|
|
189
|
+
o(B, "InjectFromBase");
|
|
190
190
|
|
|
191
191
|
var w = require("inversify");
|
|
192
192
|
|
|
193
|
-
function
|
|
193
|
+
function D(e) {
|
|
194
194
|
return (0, w.named)(e);
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
o(
|
|
197
|
+
o(D, "Named");
|
|
198
198
|
|
|
199
|
-
var
|
|
199
|
+
var j = require("inversify");
|
|
200
200
|
|
|
201
|
-
function
|
|
202
|
-
return (0,
|
|
201
|
+
function P() {
|
|
202
|
+
return (0, j.optional)();
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
o(
|
|
205
|
+
o(P, "Optional");
|
|
206
206
|
|
|
207
|
-
var
|
|
207
|
+
var M = require("inversify");
|
|
208
208
|
|
|
209
|
-
function
|
|
210
|
-
return (0,
|
|
209
|
+
function C() {
|
|
210
|
+
return (0, M.postConstruct)();
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
o(
|
|
213
|
+
o(C, "PostConstruct");
|
|
214
214
|
|
|
215
|
-
var
|
|
215
|
+
var k = require("inversify");
|
|
216
216
|
|
|
217
|
-
function
|
|
218
|
-
return (0,
|
|
217
|
+
function x() {
|
|
218
|
+
return (0, k.preDestroy)();
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
-
o(
|
|
221
|
+
o(x, "PreDestroy");
|
|
222
222
|
|
|
223
|
-
var
|
|
223
|
+
var A = require("inversify");
|
|
224
224
|
|
|
225
|
-
function
|
|
226
|
-
return (0,
|
|
225
|
+
function O(e, i) {
|
|
226
|
+
return (0, A.tagged)(e, i);
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
-
o(
|
|
229
|
+
o(O, "Tagged");
|
|
230
230
|
|
|
231
|
-
var
|
|
231
|
+
var R = require("inversify");
|
|
232
232
|
|
|
233
|
-
function
|
|
234
|
-
return (0,
|
|
233
|
+
function q() {
|
|
234
|
+
return (0, R.unmanaged)();
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
o(
|
|
237
|
+
o(q, "Unmanaged");
|
|
238
238
|
|
|
239
|
-
var
|
|
239
|
+
var F = class e extends Error {
|
|
240
240
|
static {
|
|
241
241
|
o(this, "XInjectionError");
|
|
242
242
|
}
|
|
243
243
|
name=e.name;
|
|
244
|
-
},
|
|
244
|
+
}, N = class e extends Error {
|
|
245
245
|
static {
|
|
246
246
|
o(this, "XInjectionProviderModuleError");
|
|
247
247
|
}
|
|
@@ -249,7 +249,7 @@ var N = class e extends Error {
|
|
|
249
249
|
constructor(e, i) {
|
|
250
250
|
super(`{ProviderModule.${e.toString()}} => ${i}`);
|
|
251
251
|
}
|
|
252
|
-
},
|
|
252
|
+
}, U = class e extends N {
|
|
253
253
|
static {
|
|
254
254
|
o(this, "XInjectionProviderModuleDisposedError");
|
|
255
255
|
}
|
|
@@ -257,7 +257,7 @@ var N = class e extends Error {
|
|
|
257
257
|
constructor(e) {
|
|
258
258
|
super(e, "Has been disposed! You can re-initialize it by using the `_lazyInit` method.");
|
|
259
259
|
}
|
|
260
|
-
},
|
|
260
|
+
}, G = class e extends N {
|
|
261
261
|
static {
|
|
262
262
|
o(this, "XInjectionDynamicExportsOutOfRange");
|
|
263
263
|
}
|
|
@@ -265,9 +265,17 @@ var N = class e extends Error {
|
|
|
265
265
|
constructor(e) {
|
|
266
266
|
super(e, `The 'ProviderModule.${e.toString()}' is trying to dynamically export providers/modules out of the declared range of the static exports!`);
|
|
267
267
|
}
|
|
268
|
-
},
|
|
268
|
+
}, V = class e extends N {
|
|
269
|
+
static {
|
|
270
|
+
o(this, "XInjectionProviderModuleMissingIdentifierError");
|
|
271
|
+
}
|
|
272
|
+
name=e.name;
|
|
273
|
+
constructor(e) {
|
|
274
|
+
super(e, "An `identifier` must be supplied!");
|
|
275
|
+
}
|
|
276
|
+
}, X = new (require("inversify").Container)({
|
|
269
277
|
defaultScope: "Singleton"
|
|
270
|
-
}),
|
|
278
|
+
}), L = require("inversify"), W = class {
|
|
271
279
|
static {
|
|
272
280
|
o(this, "ProviderModuleUtils");
|
|
273
281
|
}
|
|
@@ -280,47 +288,47 @@ var N = class e extends Error {
|
|
|
280
288
|
this.module = e, this.moduleNaked = e.toNaked();
|
|
281
289
|
}
|
|
282
290
|
bindToContainer(e, i) {
|
|
283
|
-
return
|
|
291
|
+
return l.isProviderIdentifier(e) ? this.bindSelfTokenToContainer(e, i) : l.isClassToken(e) ? this.bindClassTokenToContainer(e, i) : l.isValueToken(e) ? this.bindValueTokenToContainer(e) : !!l.isFactoryToken(e) && this.bindFactoryTokenToContainer(e, i);
|
|
284
292
|
}
|
|
285
293
|
bindManyToContainer(e, i) {
|
|
286
294
|
e.forEach((e => this.bindToContainer(e, i)));
|
|
287
295
|
}
|
|
288
296
|
bindSelfTokenToContainer(e, i) {
|
|
289
|
-
return this.setBindingScope(e, this.container.bind(
|
|
297
|
+
return this.setBindingScope(e, this.container.bind(l.toServiceIdentifier(e)).toSelf(), i),
|
|
290
298
|
this.moduleNaked.__isCurrentBound(e);
|
|
291
299
|
}
|
|
292
300
|
bindClassTokenToContainer(e, i) {
|
|
293
|
-
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(
|
|
301
|
+
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(l.toServiceIdentifier(e)).to(e.useClass), i))),
|
|
294
302
|
this.moduleNaked.__isCurrentBound(e);
|
|
295
303
|
}
|
|
296
304
|
bindValueTokenToContainer(e) {
|
|
297
|
-
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.container.bind(
|
|
305
|
+
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.container.bind(l.toServiceIdentifier(e)).toConstantValue(e.useValue))),
|
|
298
306
|
this.moduleNaked.__isCurrentBound(e);
|
|
299
307
|
}
|
|
300
308
|
bindFactoryTokenToContainer(e, i) {
|
|
301
|
-
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(
|
|
309
|
+
return this.setBindingOnEvent(e, this.setWhenBinding(e, this.setBindingScope(e, this.container.bind(l.toServiceIdentifier(e)).toResolvedValue(e.useFactory, l.toServiceIdentifiers(e.inject ?? [])), i))),
|
|
302
310
|
this.moduleNaked.__isCurrentBound(e);
|
|
303
311
|
}
|
|
304
312
|
setBindingScope(e, i, t) {
|
|
305
|
-
if (
|
|
306
|
-
switch (
|
|
307
|
-
case
|
|
313
|
+
if (l.isValueToken(e)) return i;
|
|
314
|
+
switch (l.getInjectionScopeByPriority(e, t)) {
|
|
315
|
+
case a.Singleton:
|
|
308
316
|
return i.inSingletonScope();
|
|
309
317
|
|
|
310
|
-
case
|
|
318
|
+
case a.Transient:
|
|
311
319
|
return i.inTransientScope();
|
|
312
320
|
|
|
313
|
-
case
|
|
321
|
+
case a.Request:
|
|
314
322
|
return i.inRequestScope();
|
|
315
323
|
}
|
|
316
324
|
}
|
|
317
325
|
setWhenBinding(e, i) {
|
|
318
|
-
if (
|
|
326
|
+
if (l.isProviderIdentifier(e)) return i;
|
|
319
327
|
const t = e.when;
|
|
320
328
|
return t ? i.when(t) : i;
|
|
321
329
|
}
|
|
322
330
|
setBindingOnEvent(e, i) {
|
|
323
|
-
if (
|
|
331
|
+
if (l.isProviderIdentifier(e)) return;
|
|
324
332
|
const t = e;
|
|
325
333
|
t.onEvent?.activation && i.onActivation(t.onEvent.activation), t.onEvent?.deactivation && i.onDeactivation(t.onEvent.deactivation);
|
|
326
334
|
}
|
|
@@ -341,9 +349,10 @@ var N = class e extends Error {
|
|
|
341
349
|
exports;
|
|
342
350
|
imports;
|
|
343
351
|
registeredBindingSideEffects;
|
|
344
|
-
constructor({identifier: e
|
|
345
|
-
const
|
|
346
|
-
this.identifier = e, this.isAppModule =
|
|
352
|
+
constructor({identifier: e, imports: i, providers: t, exports: n, defaultScope: r, dynamicExports: o, onReady: s, onDispose: d, ...c}) {
|
|
353
|
+
const a = c;
|
|
354
|
+
this.identifier = this.setIdentifier(e), this.isAppModule = a.isAppModule ?? !1,
|
|
355
|
+
this.isAppModule || this._lazyInit({
|
|
347
356
|
imports: i,
|
|
348
357
|
providers: t,
|
|
349
358
|
exports: n,
|
|
@@ -351,7 +360,7 @@ var N = class e extends Error {
|
|
|
351
360
|
dynamicExports: o,
|
|
352
361
|
onReady: s,
|
|
353
362
|
onDispose: d,
|
|
354
|
-
...
|
|
363
|
+
...c
|
|
355
364
|
});
|
|
356
365
|
}
|
|
357
366
|
get(e, i) {
|
|
@@ -366,27 +375,31 @@ var N = class e extends Error {
|
|
|
366
375
|
}));
|
|
367
376
|
}
|
|
368
377
|
onActivationEvent(e, i) {
|
|
369
|
-
this.container.onActivation(
|
|
378
|
+
this.container.onActivation(l.toServiceIdentifier(e), i);
|
|
370
379
|
}
|
|
371
380
|
onDeactivationEvent(e, i) {
|
|
372
|
-
this.container.onDeactivation(
|
|
381
|
+
this.container.onDeactivation(l.toServiceIdentifier(e), i);
|
|
373
382
|
}
|
|
374
383
|
toNaked() {
|
|
375
384
|
return this;
|
|
376
385
|
}
|
|
377
386
|
toString() {
|
|
378
|
-
return this.identifier
|
|
387
|
+
return this.identifier?.description ?? "Unknown";
|
|
388
|
+
}
|
|
389
|
+
setIdentifier(e) {
|
|
390
|
+
if (!e) throw new V(this);
|
|
391
|
+
return e;
|
|
379
392
|
}
|
|
380
393
|
prepareContainer(e) {
|
|
381
|
-
return this.isAppModule ? e.container?.() ??
|
|
382
|
-
e.container()) : new
|
|
383
|
-
parent:
|
|
394
|
+
return this.isAppModule ? e.container?.() ?? X : e.container ? (console.warn(`[xInjection]: The '${this.toString()}' module is using a dynamic container!`),
|
|
395
|
+
e.container()) : new L.Container({
|
|
396
|
+
parent: X,
|
|
384
397
|
defaultScope: this.defaultScope.inversify
|
|
385
398
|
});
|
|
386
399
|
}
|
|
387
400
|
injectImportedModules(i) {
|
|
388
401
|
i && 0 !== i.length && i.forEach((i => {
|
|
389
|
-
if ("GlobalAppModule" === i.toString()) throw new
|
|
402
|
+
if ("GlobalAppModule" === i.toString()) throw new N(this, "The 'GlobalAppModule' can't be imported!");
|
|
390
403
|
const t = i._getExportableModulesAndProviders(), n = i.dynamicExports?.(this, t);
|
|
391
404
|
void 0 !== n && this.shouldThrowWhenModuleDynamicExportsDontMatchTheStaticExports(i, t, n),
|
|
392
405
|
(n ?? t).forEach((t => {
|
|
@@ -396,9 +409,9 @@ var N = class e extends Error {
|
|
|
396
409
|
}
|
|
397
410
|
const n = t;
|
|
398
411
|
this.moduleUtils.bindToContainer({
|
|
399
|
-
scope:
|
|
400
|
-
provide:
|
|
401
|
-
useFactory: o((() =>
|
|
412
|
+
scope: l.getInjectionScopeByPriority(n, i.defaultScope.native),
|
|
413
|
+
provide: l.toServiceIdentifier(n),
|
|
414
|
+
useFactory: o((() => this._importedDependencyFactory(n, i)), "useFactory")
|
|
402
415
|
}, i.defaultScope.native);
|
|
403
416
|
}));
|
|
404
417
|
}));
|
|
@@ -424,20 +437,23 @@ var N = class e extends Error {
|
|
|
424
437
|
this.registeredBindingSideEffects.delete(e)) : this.registeredBindingSideEffects.forEach((({onUnbindEffects: e}) => e.forEach((e => e())))));
|
|
425
438
|
}
|
|
426
439
|
shouldThrowWhenModuleDynamicExportsDontMatchTheStaticExports(e, i, t) {
|
|
427
|
-
if (t.length > i.length || t.some((e => !i.includes(e)))) throw new
|
|
440
|
+
if (t.length > i.length || t.some((e => !i.includes(e)))) throw new G(e);
|
|
428
441
|
}
|
|
429
442
|
shouldThrowIfDisposed() {
|
|
430
|
-
if (null === this.container) throw new
|
|
443
|
+
if (null === this.container) throw new U(this);
|
|
444
|
+
}
|
|
445
|
+
_importedDependencyFactory(e, i) {
|
|
446
|
+
return i.get(e);
|
|
431
447
|
}
|
|
432
448
|
async _dispose() {
|
|
433
449
|
await (this.onDispose?.(this)), await this.__unbindAll(), this.container = null,
|
|
434
450
|
this.imports = null, this.providers = null, this.exports = null, this.dynamicExports = null,
|
|
435
451
|
this.registeredBindingSideEffects = null, this.isDisposed = !0;
|
|
436
452
|
}
|
|
437
|
-
_lazyInit({imports: e = [], providers: i = [], exports: t = [], defaultScope: n =
|
|
453
|
+
_lazyInit({imports: e = [], providers: i = [], exports: t = [], defaultScope: n = a.Singleton, dynamicExports: r, onReady: o, onDispose: s, ...d}) {
|
|
438
454
|
this.isDisposed = !1, this.imports = e, this.providers = i, this.exports = t, this.defaultScope = {
|
|
439
455
|
native: n,
|
|
440
|
-
inversify:
|
|
456
|
+
inversify: u(n)
|
|
441
457
|
}, this.dynamicExports = r, this.onReady = o, this.onDispose = s, this.container = this.prepareContainer({
|
|
442
458
|
...d
|
|
443
459
|
}), this.moduleUtils = new W(this), this.registeredBindingSideEffects = new Map,
|
|
@@ -467,26 +483,26 @@ var N = class e extends Error {
|
|
|
467
483
|
}
|
|
468
484
|
__bind(e) {
|
|
469
485
|
this.shouldThrowIfDisposed();
|
|
470
|
-
const i = this.container.bind(
|
|
486
|
+
const i = this.container.bind(l.toServiceIdentifier(e));
|
|
471
487
|
return this.invokeRegisteredBindingSideEffects(e, "onBind"), i;
|
|
472
488
|
}
|
|
473
489
|
__get(e, i) {
|
|
474
|
-
return this.shouldThrowIfDisposed(), this.container.get(
|
|
490
|
+
return this.shouldThrowIfDisposed(), this.container.get(l.toServiceIdentifier(e), i);
|
|
475
491
|
}
|
|
476
492
|
async __getAsync(e, i) {
|
|
477
|
-
return this.shouldThrowIfDisposed(), this.container.getAsync(
|
|
493
|
+
return this.shouldThrowIfDisposed(), this.container.getAsync(l.toServiceIdentifier(e), i);
|
|
478
494
|
}
|
|
479
495
|
__getAll(e, i) {
|
|
480
|
-
return this.shouldThrowIfDisposed(), this.container.getAll(
|
|
496
|
+
return this.shouldThrowIfDisposed(), this.container.getAll(l.toServiceIdentifier(e), i);
|
|
481
497
|
}
|
|
482
498
|
async __getAllAsync(e, i) {
|
|
483
|
-
return this.shouldThrowIfDisposed(), this.container.getAllAsync(
|
|
499
|
+
return this.shouldThrowIfDisposed(), this.container.getAllAsync(l.toServiceIdentifier(e), i);
|
|
484
500
|
}
|
|
485
501
|
__isBound(e, i) {
|
|
486
|
-
return this.shouldThrowIfDisposed(), this.container.isBound(
|
|
502
|
+
return this.shouldThrowIfDisposed(), this.container.isBound(l.toServiceIdentifier(e), i);
|
|
487
503
|
}
|
|
488
504
|
__isCurrentBound(e, i) {
|
|
489
|
-
return this.shouldThrowIfDisposed(), this.container.isCurrentBound(
|
|
505
|
+
return this.shouldThrowIfDisposed(), this.container.isCurrentBound(l.toServiceIdentifier(e), i);
|
|
490
506
|
}
|
|
491
507
|
__takeSnapshot() {
|
|
492
508
|
this.shouldThrowIfDisposed(), this.container.snapshot();
|
|
@@ -496,20 +512,20 @@ var N = class e extends Error {
|
|
|
496
512
|
}
|
|
497
513
|
async __rebind(e) {
|
|
498
514
|
this.shouldThrowIfDisposed();
|
|
499
|
-
const i = await this.container.rebind(
|
|
515
|
+
const i = await this.container.rebind(l.toServiceIdentifier(e));
|
|
500
516
|
return this.invokeRegisteredBindingSideEffects(e, "onRebind"), i;
|
|
501
517
|
}
|
|
502
518
|
__rebindSync(e) {
|
|
503
519
|
this.shouldThrowIfDisposed();
|
|
504
|
-
const i = this.container.rebindSync(
|
|
520
|
+
const i = this.container.rebindSync(l.toServiceIdentifier(e));
|
|
505
521
|
return this.invokeRegisteredBindingSideEffects(e, "onRebind"), i;
|
|
506
522
|
}
|
|
507
523
|
async __unbind(e) {
|
|
508
|
-
this.shouldThrowIfDisposed(), await this.container.unbind(
|
|
524
|
+
this.shouldThrowIfDisposed(), await this.container.unbind(l.toServiceIdentifier(e)),
|
|
509
525
|
this.removeRegisteredBindingSideEffects(e);
|
|
510
526
|
}
|
|
511
527
|
__unbindSync(e) {
|
|
512
|
-
this.shouldThrowIfDisposed(), this.container.unbindSync(
|
|
528
|
+
this.shouldThrowIfDisposed(), this.container.unbindSync(l.toServiceIdentifier(e)),
|
|
513
529
|
this.removeRegisteredBindingSideEffects(e);
|
|
514
530
|
}
|
|
515
531
|
async __unbindAll() {
|
|
@@ -522,13 +538,13 @@ var N = class e extends Error {
|
|
|
522
538
|
nakedModule=this;
|
|
523
539
|
isLoaded=!1;
|
|
524
540
|
constructor() {
|
|
525
|
-
super(
|
|
541
|
+
super(f.buildInternalConstructorParams({
|
|
526
542
|
identifier: Symbol(d),
|
|
527
543
|
isAppModule: !0
|
|
528
544
|
}));
|
|
529
545
|
}
|
|
530
546
|
register(e) {
|
|
531
|
-
if (this.isLoaded) throw new
|
|
547
|
+
if (this.isLoaded) throw new F(`The '${this.toString()}' has already been registered!`);
|
|
532
548
|
return this.nakedModule._lazyInit(e), this.isLoaded = !0, this;
|
|
533
549
|
}
|
|
534
550
|
toNaked() {
|