@adimm/x-injection 0.7.0 → 1.1.5

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/dist/index.d.ts CHANGED
@@ -168,6 +168,7 @@ interface IProviderModuleNaked extends IProviderModule {
168
168
  readonly onDispose: ProviderModuleOptions['onDispose'];
169
169
  /** Can be used to override all the _imported_ providers _before_ the binding process. */
170
170
  readonly importedProvidersMap: ProviderModuleOptionsInternal['importedProvidersMap'];
171
+ readonly registeredSideEffects: RegisteredSideEffects;
171
172
  /** It'll _completely_ re-init the `module` with the provided {@link LazyInitOptions | options}. */
172
173
  _lazyInit(options: LazyInitOptions): IProviderModule;
173
174
  /** Can be used to get the list of all the imported modules of this module. */
@@ -180,12 +181,19 @@ interface IProviderModuleNaked extends IProviderModule {
180
181
  * Can be used to execute the provided {@link cb | callback} whenever a _new_ {@link https://inversify.io/docs/fundamentals/binding/ | binding}
181
182
  * is registered for the {@link provider}.
182
183
  *
183
- * **Note:** _This is not the same as the {@link onActivationEvent}!_
184
- *
185
184
  * @param provider The {@link ProviderToken}.
186
185
  * @param cb The `callback` to be invoked.
187
186
  */
188
187
  _onBind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
188
+ /**
189
+ * Can be used to execute the provided {@link cb | callback} whenever the
190
+ * {@link IProviderModule.get | get} method is invoked.
191
+ *
192
+ * @param provider The {@link ProviderToken}.
193
+ * @param once When set to `true` it'll invoke the provided {@link cb | callback} only once.
194
+ * @param cb The `callback` to be invoked.
195
+ */
196
+ _onGet<T>(provider: ProviderToken<T>, once: boolean, cb: () => Promise<void> | void): void;
189
197
  /**
190
198
  * Can be used to execute the provided {@link cb | callback} whenever an existing {@link https://inversify.io/docs/fundamentals/binding/ | binding}
191
199
  * is re-registered for the {@link provider}.
@@ -197,8 +205,7 @@ interface IProviderModuleNaked extends IProviderModule {
197
205
  /**
198
206
  * Can be used to execute the provided {@link cb | callback} whenever a {@link provider} is `unbound`.
199
207
  *
200
- * **Note:** _This is not the same as the {@link onDeactivationEvent}!_
201
- * _Also the {@link _onBind}, {@link __rebind} and {@link _onUnbind} registered callbacks will be removed._
208
+ * **Note:** _All the {@link _onBind}, {@link _onGet}, {@link _onRebind} and {@link _onUnbind} registered callbacks will be removed_
202
209
  *
203
210
  * @param provider The {@link ProviderToken}.
204
211
  * @param cb The `callback` to be invoked.
@@ -318,6 +325,23 @@ interface IProviderModuleNaked extends IProviderModule {
318
325
  __unbindAll(): Promise<void>;
319
326
  }
320
327
  type LazyInitOptions = Except<ProviderModuleOptions & ProviderModuleOptionsInternal, 'identifier' | 'isAppModule'>;
328
+ type RegisteredSideEffects = Map<ProviderToken, {
329
+ onBindEffects: OnBindEffects[];
330
+ onGetEffects: OnGetEffects[];
331
+ onRebindEffects: OnRebindEffects[];
332
+ onUnbindEffects: OnUnbindEffects[];
333
+ }>;
334
+ type OnBindEffects = () => Promise<void> | void;
335
+ type OnGetEffects = {
336
+ once: boolean;
337
+ invoked: boolean;
338
+ cb: () => Promise<void> | void;
339
+ };
340
+ type OnRebindEffects = () => Promise<void> | void;
341
+ type OnUnbindEffects = {
342
+ registerModule?: symbol;
343
+ cb: () => Promise<void> | void;
344
+ };
321
345
 
322
346
  /**
323
347
  * The low-level App Container.
@@ -399,12 +423,10 @@ declare class ProviderModule implements IProviderModule {
399
423
  protected readonly providers: IProviderModuleNaked['providers'];
400
424
  protected readonly importedProviders: IProviderModuleNaked['importedProviders'];
401
425
  protected readonly exports: IProviderModuleNaked['exports'];
402
- private readonly registeredBindingSideEffects;
426
+ protected readonly registeredSideEffects: IProviderModuleNaked['registeredSideEffects'];
403
427
  constructor({ identifier, imports, providers, exports, defaultScope, markAsGlobal, dynamicExports, onReady, onDispose, ..._internalParams }: ProviderModuleOptions);
404
428
  get<T>(provider: ProviderToken<T>, isOptional?: boolean): T;
405
429
  getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
406
- onActivationEvent<T>(provider: ProviderToken<T>, cb: BindingActivation<T>): void;
407
- onDeactivationEvent<T>(provider: ProviderToken<T>, cb: BindingDeactivation<T>): void;
408
430
  toNaked(): IProviderModuleNaked;
409
431
  clone(options?: Partial<ProviderModuleOptions>): IProviderModule;
410
432
  dispose(): Promise<void>;
@@ -413,9 +435,11 @@ declare class ProviderModule implements IProviderModule {
413
435
  private prepareContainer;
414
436
  private injectImportedModules;
415
437
  private injectProviders;
438
+ private onUnbindInternal;
416
439
  private registerBindingSideEffect;
417
440
  private invokeRegisteredBindingSideEffects;
418
441
  private removeRegisteredBindingSideEffects;
442
+ private removeOnUnbindEffectsFromImportedModule;
419
443
  private shouldThrowIfDisposed;
420
444
  /**
421
445
  * **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
@@ -447,6 +471,12 @@ declare class ProviderModule implements IProviderModule {
447
471
  * See {@link IProviderModuleNaked._onBind}.
448
472
  */
449
473
  protected _onBind<T>(provider: ProviderToken<T>, cb: () => Promise<void> | void): void;
474
+ /**
475
+ * **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
476
+ *
477
+ * See {@link IProviderModuleNaked._onGet}.
478
+ */
479
+ protected _onGet<T>(provider: ProviderToken<T>, once: boolean, cb: () => Promise<void> | void): void;
450
480
  /**
451
481
  * **Publicly visible when the instance is casted to {@link IProviderModuleNaked}.**
452
482
  *
@@ -731,18 +761,6 @@ interface IProviderModule {
731
761
  * ```
732
762
  */
733
763
  getMany<D extends (ProviderModuleGetManyParam<any> | ProviderToken)[]>(...deps: D | unknown[]): ProviderModuleGetManySignature<D>;
734
- /**
735
- * Adds an activation handler for the {@link provider}.
736
- *
737
- * See {@link https://inversify.io/docs/api/container/#onactivation} for more details.
738
- */
739
- onActivationEvent<T>(provider: ProviderToken<T>, cb: BindingActivation<T>): void;
740
- /**
741
- * Adds a deactivation handler for the {@link provider}.
742
- *
743
- * See {@link https://inversify.io/docs/api/container/#ondeactivation} for more details.
744
- */
745
- onDeactivationEvent<T>(provider: ProviderToken<T>, cb: BindingDeactivation<T>): void;
746
764
  /**
747
765
  * Casts the current module type to the {@link IProviderModuleNaked} type.
748
766
  *
@@ -800,12 +818,6 @@ declare function Named(name: MetadataName): MethodDecorator & ParameterDecorator
800
818
  /** See {@link https://inversify.io/docs/api/decorator/#optional} for more details. */
801
819
  declare function Optional(): MethodDecorator & ParameterDecorator & PropertyDecorator;
802
820
 
803
- /** See {@link https://inversify.io/docs/api/decorator/#postconstruct} for more details. */
804
- declare function PostConstruct(): MethodDecorator;
805
-
806
- /** See {@link https://inversify.io/docs/api/decorator/#predestroy} for more details. */
807
- declare function PreDestroy(): MethodDecorator;
808
-
809
821
  /** See {@link https://inversify.io/docs/api/decorator/#tagged} for more details. */
810
822
  declare function Tagged(key: MetadataTag, value: unknown): MethodDecorator & ParameterDecorator & PropertyDecorator;
811
823
 
@@ -880,4 +892,4 @@ declare function isFunction(v: any): boolean;
880
892
 
881
893
  declare function isClassOrFunction(value: any): value is Function | Class<any>;
882
894
 
883
- export { AppModule, type AppModuleOptions, type DependencyProvider, type DynamicExports, GLOBAL_APP_MODULE_ID, GlobalAppModule, GlobalContainer, type IAppModule, type IProviderModule, type IProviderModuleNaked, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleGlobalMarkError, InjectionProviderModuleMissingIdentifierError, InjectionScope, type LazyInitOptions, MultiInject, Named, type OnEvent, Optional, PostConstruct, PreDestroy, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, type ProviderModuleGetManyParam, type ProviderModuleGetManySignature, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, type StaticExports, Tagged, Unmanaged, bindingScopeToInjectionScope, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
895
+ export { AppModule, type AppModuleOptions, type DependencyProvider, type DynamicExports, GLOBAL_APP_MODULE_ID, GlobalAppModule, GlobalContainer, type IAppModule, type IProviderModule, type IProviderModuleNaked, Inject, InjectFromBase, Injectable, InjectionError, InjectionProviderModuleDisposedError, InjectionProviderModuleError, InjectionProviderModuleGlobalMarkError, InjectionProviderModuleMissingIdentifierError, InjectionScope, type LazyInitOptions, MultiInject, Named, type OnEvent, Optional, type ProviderClassToken, type ProviderFactoryToken, type ProviderIdentifier, ProviderModule, type ProviderModuleGetManyParam, type ProviderModuleGetManySignature, ProviderModuleHelpers, type ProviderModuleOptions, type ProviderModuleOptionsInternal, type ProviderOptions, type ProviderScopeOption, type ProviderToken, ProviderTokenHelpers, type ProviderValueToken, type StaticExports, Tagged, Unmanaged, bindingScopeToInjectionScope, injectionScopeToBindingScope, isClass, isClassOrFunction, isFunction, isPlainObject };
package/dist/index.js CHANGED
@@ -48,7 +48,7 @@ function h(e) {
48
48
  return "function" == typeof e;
49
49
  }
50
50
 
51
- function p(e) {
51
+ function f(e) {
52
52
  return "function" == typeof e && !Function.prototype.toString.call(e).startsWith("class ");
53
53
  }
54
54
 
@@ -56,7 +56,7 @@ function l(e) {
56
56
  return "[object Object]" === Object.prototype.toString.call(e);
57
57
  }
58
58
 
59
- function f(e) {
59
+ function p(e) {
60
60
  if (!1 === l(e)) return !1;
61
61
  const i = e.constructor;
62
62
  if (void 0 === i) return !0;
@@ -68,16 +68,16 @@ function v(e) {
68
68
  return void 0 === e ? n() : n(d(e));
69
69
  }
70
70
 
71
- i(u, "isClass"), i(h, "isClassOrFunction"), i(p, "isFunction"), i(l, "isObject"),
72
- i(f, "isPlainObject"), function(e) {
71
+ i(u, "isClass"), i(h, "isClassOrFunction"), i(f, "isFunction"), i(l, "isObject"),
72
+ i(p, "isPlainObject"), function(e) {
73
73
  function t(e) {
74
- return y(e) && "useClass" in e;
74
+ return b(e) && "useClass" in e;
75
75
  }
76
76
  function n(e) {
77
- return y(e) && "useValue" in e;
77
+ return b(e) && "useValue" in e;
78
78
  }
79
79
  function o(e) {
80
- return y(e) && "useFactory" in e;
80
+ return b(e) && "useFactory" in e;
81
81
  }
82
82
  function r(e) {
83
83
  return "string" == typeof e || "symbol" == typeof e || h(e);
@@ -93,7 +93,7 @@ i(f, "isPlainObject"), function(e) {
93
93
  ...i,
94
94
  provide: i?.provide ?? e,
95
95
  useClass: i?.useClass ?? e
96
- } : p(e) ? {
96
+ } : f(e) ? {
97
97
  ...i,
98
98
  provide: i?.provide ?? e,
99
99
  useFactory: i?.useFactory ?? e
@@ -106,7 +106,7 @@ i(f, "isPlainObject"), function(e) {
106
106
  return m(e) ?? S(e) ?? i;
107
107
  }
108
108
  function g(e) {
109
- if (y(e)) return e;
109
+ if (b(e)) return e;
110
110
  }
111
111
  function m(e) {
112
112
  const i = g(e);
@@ -118,8 +118,8 @@ i(f, "isPlainObject"), function(e) {
118
118
  const t = c(i)?.scope;
119
119
  return t ? a(t) : void 0;
120
120
  }
121
- function y(e) {
122
- return f(e) && "object" == typeof e && "provide" in e;
121
+ function b(e) {
122
+ return p(e) && "object" == typeof e && "provide" in e;
123
123
  }
124
124
  i(t, "isClassToken"), e.isClassToken = t, i(n, "isValueToken"), e.isValueToken = n,
125
125
  i(o, "isFactoryToken"), e.isFactoryToken = o, i(r, "isProviderIdentifier"), e.isProviderIdentifier = r,
@@ -127,7 +127,7 @@ i(f, "isPlainObject"), function(e) {
127
127
  e.toServiceIdentifiers = d, i(l, "toDependencyProviderWithOptions"), e.toDependencyProviderWithOptions = l,
128
128
  i(v, "getInjectionScopeByPriority"), e.getInjectionScopeByPriority = v, i(g, "tryGetProviderOptions"),
129
129
  e.tryGetProviderOptions = g, i(m, "tryGetScopeFromProvider"), e.tryGetScopeFromProvider = m,
130
- i(S, "tryGetDecoratorScopeFromClass"), e.tryGetDecoratorScopeFromClass = S, i(y, "hasProvideProperty");
130
+ i(S, "tryGetDecoratorScopeFromClass"), e.tryGetDecoratorScopeFromClass = S, i(b, "hasProvideProperty");
131
131
  }(o || (o = {})), function(e) {
132
132
  function t(e) {
133
133
  return e;
@@ -149,16 +149,16 @@ i(m, "Inject");
149
149
 
150
150
  import { multiInject as S } from "inversify";
151
151
 
152
- function y(e) {
152
+ function b(e) {
153
153
  return S(o.toServiceIdentifier(e));
154
154
  }
155
155
 
156
- i(y, "MultiInject");
156
+ i(b, "MultiInject");
157
157
 
158
- import { injectFromBase as b } from "inversify";
158
+ import { injectFromBase as y } from "inversify";
159
159
 
160
160
  function I(e) {
161
- return b(e);
161
+ return y(e);
162
162
  }
163
163
 
164
164
  i(I, "InjectFromBase");
@@ -171,52 +171,36 @@ function T(e) {
171
171
 
172
172
  i(T, "Named");
173
173
 
174
- import { optional as k } from "inversify";
175
-
176
- function M() {
177
- return k();
178
- }
179
-
180
- i(M, "Optional");
181
-
182
- import { postConstruct as w } from "inversify";
183
-
184
- function B() {
185
- return w();
186
- }
187
-
188
- i(B, "PostConstruct");
174
+ import { optional as M } from "inversify";
189
175
 
190
- import { preDestroy as _ } from "inversify";
191
-
192
- function P() {
193
- return _();
176
+ function k() {
177
+ return M();
194
178
  }
195
179
 
196
- i(P, "PreDestroy");
180
+ i(k, "Optional");
197
181
 
198
- import { tagged as D } from "inversify";
182
+ import { tagged as w } from "inversify";
199
183
 
200
- function A(e, i) {
201
- return D(e, i);
184
+ function _(e, i) {
185
+ return w(e, i);
202
186
  }
203
187
 
204
- i(A, "Tagged");
188
+ i(_, "Tagged");
205
189
 
206
- import { unmanaged as C } from "inversify";
190
+ import { unmanaged as P } from "inversify";
207
191
 
208
- function R() {
209
- return C();
192
+ function B() {
193
+ return P();
210
194
  }
211
195
 
212
- i(R, "Unmanaged");
196
+ i(B, "Unmanaged");
213
197
 
214
- var j = class e extends Error {
198
+ var A = class e extends Error {
215
199
  static {
216
200
  i(this, "InjectionError");
217
201
  }
218
202
  name=e.name;
219
- }, x = class e extends Error {
203
+ }, D = class e extends Error {
220
204
  static {
221
205
  i(this, "InjectionProviderModuleError");
222
206
  }
@@ -224,7 +208,7 @@ var j = class e extends Error {
224
208
  constructor(e, i) {
225
209
  super(`{ProviderModule.${e.toString()}} => ${i}`);
226
210
  }
227
- }, G = class e extends x {
211
+ }, C = class e extends D {
228
212
  static {
229
213
  i(this, "InjectionProviderModuleDisposedError");
230
214
  }
@@ -232,7 +216,7 @@ var j = class e extends Error {
232
216
  constructor(e) {
233
217
  super(e, "Has been disposed! You can re-initialize it by using the `_lazyInit` method.");
234
218
  }
235
- }, F = class e extends x {
219
+ }, R = class e extends D {
236
220
  static {
237
221
  i(this, "InjectionProviderModuleMissingIdentifierError");
238
222
  }
@@ -240,7 +224,7 @@ var j = class e extends Error {
240
224
  constructor(e) {
241
225
  super(e, "An `identifier` must be supplied!");
242
226
  }
243
- }, O = class e extends x {
227
+ }, j = class e extends D {
244
228
  static {
245
229
  i(this, "InjectionProviderModuleGlobalMarkError");
246
230
  }
@@ -250,15 +234,15 @@ var j = class e extends Error {
250
234
  }
251
235
  };
252
236
 
253
- import { Container as N } from "inversify";
237
+ import { Container as x } from "inversify";
254
238
 
255
- var U = new N({
239
+ var G = new x({
256
240
  defaultScope: "Singleton"
257
241
  });
258
242
 
259
- import { Container as V } from "inversify";
243
+ import { Container as F } from "inversify";
260
244
 
261
- var q = class {
245
+ var O = class {
262
246
  static {
263
247
  i(this, "ProviderModuleUtils");
264
248
  }
@@ -267,7 +251,7 @@ var q = class {
267
251
  }
268
252
  module;
269
253
  moduleNaked;
270
- appModule=H;
254
+ appModule=q;
271
255
  constructor(e, i) {
272
256
  this.module = e, this.moduleNaked = e.toNaked(), this.appModule = i.appModule?.() ?? this.appModule,
273
257
  this.checkIfShouldBeAddedToTheGlobalRegister();
@@ -276,7 +260,7 @@ var q = class {
276
260
  return o.isProviderIdentifier(e) ? this.bindSelfTokenToContainer(e, i) : o.isClassToken(e) ? this.bindClassTokenToContainer(e, i) : o.isValueToken(e) ? this.bindValueTokenToContainer(e) : !!o.isFactoryToken(e) && this.bindFactoryTokenToContainer(e, i);
277
261
  }
278
262
  checkIfShouldBeAddedToTheGlobalRegister() {
279
- !this.moduleNaked.isAppModule && this.module.isMarkedAsGlobal && $.add(this.module);
263
+ !this.moduleNaked.isAppModule && this.module.isMarkedAsGlobal && N.add(this.module);
280
264
  }
281
265
  bindSelfTokenToContainer(e, i) {
282
266
  return this.setBindingScope(e, this.container.bind(o.toServiceIdentifier(e)).toSelf(), i),
@@ -317,7 +301,7 @@ var q = class {
317
301
  const t = e;
318
302
  t.onEvent?.activation && i.onActivation(t.onEvent.activation), t.onEvent?.deactivation && i.onDeactivation(t.onEvent.deactivation);
319
303
  }
320
- }, W = class e {
304
+ }, U = class e {
321
305
  static {
322
306
  i(this, "ProviderModule");
323
307
  }
@@ -336,7 +320,7 @@ var q = class {
336
320
  providers;
337
321
  importedProviders;
338
322
  exports;
339
- registeredBindingSideEffects;
323
+ registeredSideEffects;
340
324
  constructor({identifier: e, imports: i, providers: t, exports: n, defaultScope: o, markAsGlobal: r, dynamicExports: s, onReady: d, onDispose: a, ...c}) {
341
325
  const u = c;
342
326
  this.identifier = this.setIdentifier(e), this.isDisposed = u.isDisposed ?? !1, this.isAppModule = u.isAppModule ?? !1,
@@ -359,22 +343,15 @@ var q = class {
359
343
  }
360
344
  getMany(...e) {
361
345
  return e.map((e => {
362
- const i = f(e) && "provider" in e;
346
+ const i = p(e) && "provider" in e;
363
347
  return this.get(i ? e.provider : e, !!i && e.isOptional);
364
348
  }));
365
349
  }
366
- onActivationEvent(e, i) {
367
- this.shouldThrowIfDisposed(), this.container.onActivation(o.toServiceIdentifier(e), i);
368
- }
369
- onDeactivationEvent(e, i) {
370
- this.shouldThrowIfDisposed(), this.container.onDeactivation(o.toServiceIdentifier(e), i);
371
- }
372
350
  toNaked() {
373
351
  return this;
374
352
  }
375
353
  clone(i) {
376
- const t = i;
377
- return new e(r.buildInternalConstructorParams({
354
+ const t = i, n = new e(r.buildInternalConstructorParams({
378
355
  isAppModule: this.isAppModule,
379
356
  markAsGlobal: this.isMarkedAsGlobal,
380
357
  identifier: this.identifier,
@@ -388,67 +365,101 @@ var q = class {
388
365
  exports: [ ...this.exports ],
389
366
  ...t
390
367
  }));
368
+ return n.registeredSideEffects = new Map(this.registeredSideEffects), n;
391
369
  }
392
370
  async dispose() {
393
371
  await (this.onDispose?.(this)), await this.__unbindAll(), this.container = null,
394
372
  this.imports = null, this.providers = null, this.importedProviders = null, this.exports = null,
395
- this.dynamicExports = null, this.registeredBindingSideEffects = null, this.isDisposed = !0;
373
+ this.dynamicExports = null, this.registeredSideEffects = null, this.isDisposed = !0;
396
374
  }
397
375
  toString() {
398
376
  return this.identifier?.description ?? "Unknown";
399
377
  }
400
378
  setIdentifier(e) {
401
- if (!e) throw new F(this);
379
+ if (!e) throw new R(this);
402
380
  return e;
403
381
  }
404
382
  prepareContainer(e) {
405
- return this.isAppModule ? e.container?.() ?? U : e.container ? (console.warn(`[xInjection]: The '${this.toString()}' module is using a dynamic container!`),
406
- e.container()) : new V({
407
- parent: U,
383
+ return this.isAppModule ? e.container?.() ?? G : e.container ? (console.warn(`[xInjection]: The '${this.toString()}' module is using a dynamic container!`),
384
+ e.container()) : new F({
385
+ parent: G,
408
386
  defaultScope: this.defaultScope.inversify
409
387
  });
410
388
  }
411
389
  injectImportedModules(t) {
412
390
  t && 0 !== t.length && t.forEach((t => {
413
- if ("GlobalAppModule" === t.toString()) throw new x(this, "The 'GlobalAppModule' can't be imported!");
391
+ if ("GlobalAppModule" === t.toString()) throw new D(this, "The 'GlobalAppModule' can't be imported!");
414
392
  const n = (t = "function" == typeof t ? t() : t)._getExportableModulesAndProviders(), r = t.dynamicExports?.(this, n);
415
393
  (r ?? n).forEach((n => {
416
394
  if (n instanceof e) {
417
395
  const e = n.toNaked();
418
396
  return void this.injectImportedModules([ e ]);
419
397
  }
420
- const r = n, s = this.importedProvidersMap({
398
+ const r = n, s = o.toServiceIdentifier(r), d = this.importedProvidersMap({
421
399
  scope: o.getInjectionScopeByPriority(r, t.defaultScope.native),
422
- provide: o.toServiceIdentifier(r),
400
+ provide: s,
423
401
  useFactory: i((() => t.get(r)), "useFactory")
424
402
  }, r, t);
425
- this.importedProviders.set(t, [ ...this.importedProviders.get(t) ?? [], s ]), this.moduleUtils.bindToContainer(s, t.defaultScope.native),
426
- t._onUnbind(r, (() => this.__unbind(s)));
403
+ this.importedProviders.set(t, [ ...this.importedProviders.get(t) ?? [], d ]), this.moduleUtils.bindToContainer(d, t.defaultScope.native);
404
+ const a = t;
405
+ a.onUnbindInternal(r, this.identifier, (() => this.__unbind(d))), this._onUnbind(d, (() => {
406
+ this.removeOnUnbindEffectsFromImportedModule(s, a);
407
+ }));
427
408
  }));
428
409
  }));
429
410
  }
430
411
  injectProviders() {
431
412
  this.providers.forEach((e => this.moduleUtils.bindToContainer(e, this.defaultScope.native)));
432
413
  }
433
- registerBindingSideEffect(e, i, t) {
434
- this.registeredBindingSideEffects.has(e) || this.registeredBindingSideEffects.set(e, {
414
+ onUnbindInternal(e, i, t) {
415
+ this.shouldThrowIfDisposed(), this.registerBindingSideEffect(e, "unbind", t, {
416
+ registerModule: i
417
+ });
418
+ }
419
+ registerBindingSideEffect(e, i, t, n) {
420
+ const r = o.toServiceIdentifier(e);
421
+ this.registeredSideEffects.has(r) || this.registeredSideEffects.set(r, {
435
422
  onBindEffects: [],
423
+ onGetEffects: [],
436
424
  onRebindEffects: [],
437
425
  onUnbindEffects: []
438
426
  });
439
- const n = this.registeredBindingSideEffects.get(e);
440
- "bind" === i ? n.onBindEffects.push(t) : "rebind" === i ? n.onRebindEffects.push(t) : n.onUnbindEffects.push(t);
427
+ const s = this.registeredSideEffects.get(r);
428
+ "bind" === i ? s.onBindEffects.push(t) : "get" === i ? s.onGetEffects.push({
429
+ once: n.once,
430
+ invoked: !1,
431
+ cb: t
432
+ }) : "rebind" === i ? s.onRebindEffects.push(t) : "unbind" === i && s.onUnbindEffects.push({
433
+ registerModule: n?.registerModule,
434
+ cb: t
435
+ });
441
436
  }
442
437
  invokeRegisteredBindingSideEffects(e, i) {
443
- const t = this.registeredBindingSideEffects.get(e);
444
- t && t[`${i}Effects`].forEach((e => e()));
438
+ const t = o.toServiceIdentifier(e), n = this.registeredSideEffects.get(t);
439
+ n && n[`${i}Effects`].forEach((e => {
440
+ if ("function" == typeof e) return e();
441
+ if ("onGet" === i) {
442
+ const i = e;
443
+ if (i.invoked && i.once) return;
444
+ i.invoked = !0;
445
+ }
446
+ e.cb();
447
+ }));
445
448
  }
446
449
  removeRegisteredBindingSideEffects(e) {
447
- this.registeredBindingSideEffects && ("all" !== e ? this.registeredBindingSideEffects.has(e) && (this.registeredBindingSideEffects.get(e)?.onUnbindEffects.forEach((e => e())),
448
- this.registeredBindingSideEffects.delete(e)) : this.registeredBindingSideEffects.forEach((({onUnbindEffects: e}) => e.forEach((e => e())))));
450
+ if (!this.registeredSideEffects) return;
451
+ if ("all" === e) return this.registeredSideEffects.forEach((({onUnbindEffects: e}) => e.forEach((e => e.cb())))),
452
+ void this.registeredSideEffects.clear();
453
+ const i = o.toServiceIdentifier(e);
454
+ this.registeredSideEffects.has(i) && (this.registeredSideEffects.get(i)?.onUnbindEffects.forEach((e => e.cb())),
455
+ this.registeredSideEffects.delete(i));
456
+ }
457
+ removeOnUnbindEffectsFromImportedModule(e, i) {
458
+ const t = i.registeredSideEffects.get(e);
459
+ t && (t.onUnbindEffects = t.onUnbindEffects.filter((e => e.registerModule !== this.identifier)));
449
460
  }
450
461
  shouldThrowIfDisposed() {
451
- if (null === this.container) throw new G(this);
462
+ if (null === this.container) throw new C(this);
452
463
  }
453
464
  _lazyInit({markAsGlobal: e, imports: i = [], providers: t = [], exports: n = [], defaultScope: o = s.Singleton, dynamicExports: r, onReady: a, onDispose: c, ...u}) {
454
465
  return this.isMarkedAsGlobal = e ?? !1, this.isDisposed = !1, this.imports = i,
@@ -459,9 +470,8 @@ var q = class {
459
470
  }, this.dynamicExports = r, this.onReady = a, this.onDispose = c, this.importedProvidersMap = u.importedProvidersMap ?? (e => e),
460
471
  this.container = this.prepareContainer({
461
472
  ...u
462
- }), this.moduleUtils = new q(this, u), this.registeredBindingSideEffects = new Map,
463
- this.injectImportedModules(this._getImportedModules()), this.injectProviders(),
464
- this.onReady?.(this), this;
473
+ }), this.moduleUtils = new O(this, u), this.registeredSideEffects = new Map, this.injectImportedModules(this._getImportedModules()),
474
+ this.injectProviders(), this.onReady?.(this), this;
465
475
  }
466
476
  _getImportedModules() {
467
477
  return this.shouldThrowIfDisposed(), this.imports;
@@ -475,6 +485,12 @@ var q = class {
475
485
  _onBind(e, i) {
476
486
  this.shouldThrowIfDisposed(), this.registerBindingSideEffect(e, "bind", i);
477
487
  }
488
+ _onGet(e, i, t) {
489
+ if (this.shouldThrowIfDisposed(), "boolean" != typeof i) throw new D(this, `The 'once' parameter is required when using the '${this._onGet.name}' method!`);
490
+ this.registerBindingSideEffect(e, "get", t, {
491
+ once: i
492
+ });
493
+ }
478
494
  _onRebind(e, i) {
479
495
  this.shouldThrowIfDisposed(), this.registerBindingSideEffect(e, "rebind", i);
480
496
  }
@@ -490,7 +506,8 @@ var q = class {
490
506
  return this.invokeRegisteredBindingSideEffects(e, "onBind"), i;
491
507
  }
492
508
  __get(e, i) {
493
- return this.shouldThrowIfDisposed(), this.container.get(o.toServiceIdentifier(e), i);
509
+ return this.shouldThrowIfDisposed(), this.invokeRegisteredBindingSideEffects(e, "onGet"),
510
+ this.container.get(o.toServiceIdentifier(e), i);
494
511
  }
495
512
  async __getAsync(e, i) {
496
513
  return this.shouldThrowIfDisposed(), this.container.getAsync(o.toServiceIdentifier(e), i);
@@ -534,7 +551,7 @@ var q = class {
534
551
  async __unbindAll() {
535
552
  this.shouldThrowIfDisposed(), await this.container.unbindAll(), this.removeRegisteredBindingSideEffects("all");
536
553
  }
537
- }, $ = new Set, z = class extends W {
554
+ }, N = new Set, V = class extends U {
538
555
  static {
539
556
  i(this, "GlobalAppModule");
540
557
  }
@@ -547,7 +564,7 @@ var q = class {
547
564
  }));
548
565
  }
549
566
  register(e) {
550
- if (this.isLoaded) throw new j(`The '${this.toString()}' has already been registered!`);
567
+ if (this.isLoaded) throw new A(`The '${this.toString()}' has already been registered!`);
551
568
  return this.nakedModule._lazyInit(e), this.checkIfRegisteredModulesHaveGlobalMark(this.toNaked(), this.imports),
552
569
  this.isLoaded = !0, this;
553
570
  }
@@ -559,14 +576,14 @@ var q = class {
559
576
  }
560
577
  checkIfRegisteredModulesHaveGlobalMark(e, i, t = !1) {
561
578
  i.forEach((i => {
562
- if (i instanceof W) {
563
- if (i.isMarkedAsGlobal) return $.delete(i), void (i.exports && this.checkIfRegisteredModulesHaveGlobalMark(i, i.exports, !0));
564
- throw new O(i, t ? `Is not marked as \`global\` but has been imported into the \`AppModule\`via the \`${e.toString()}\` module!` : "Is not marked as `global` but has been imported into the `AppModule`!");
579
+ if (i instanceof U) {
580
+ if (i.isMarkedAsGlobal) return N.delete(i), void (i.exports && this.checkIfRegisteredModulesHaveGlobalMark(i, i.exports, !0));
581
+ throw new j(i, t ? `Is not marked as \`global\` but has been imported into the \`AppModule\`via the \`${e.toString()}\` module!` : "Is not marked as `global` but has been imported into the `AppModule`!");
565
582
  }
566
- })), t || $.forEach((e => {
567
- throw new O(e, "Is marked as 'global' and has not been imported into the 'AppModule'!");
583
+ })), t || N.forEach((e => {
584
+ throw new j(e, "Is marked as 'global' and has not been imported into the 'AppModule'!");
568
585
  }));
569
586
  }
570
- }, H = new z;
587
+ }, q = new V;
571
588
 
572
- export { H as AppModule, t as GLOBAL_APP_MODULE_ID, z as GlobalAppModule, U as GlobalContainer, m as Inject, I as InjectFromBase, v as Injectable, j as InjectionError, G as InjectionProviderModuleDisposedError, x as InjectionProviderModuleError, O as InjectionProviderModuleGlobalMarkError, F as InjectionProviderModuleMissingIdentifierError, s as InjectionScope, y as MultiInject, T as Named, M as Optional, B as PostConstruct, P as PreDestroy, W as ProviderModule, r as ProviderModuleHelpers, o as ProviderTokenHelpers, A as Tagged, R as Unmanaged, a as bindingScopeToInjectionScope, d as injectionScopeToBindingScope, u as isClass, h as isClassOrFunction, p as isFunction, f as isPlainObject };//# sourceMappingURL=index.js.map
589
+ export { q as AppModule, t as GLOBAL_APP_MODULE_ID, V as GlobalAppModule, G as GlobalContainer, m as Inject, I as InjectFromBase, v as Injectable, A as InjectionError, C as InjectionProviderModuleDisposedError, D as InjectionProviderModuleError, j as InjectionProviderModuleGlobalMarkError, R as InjectionProviderModuleMissingIdentifierError, s as InjectionScope, b as MultiInject, T as Named, k as Optional, U as ProviderModule, r as ProviderModuleHelpers, o as ProviderTokenHelpers, _ as Tagged, B as Unmanaged, a as bindingScopeToInjectionScope, d as injectionScopeToBindingScope, u as isClass, h as isClassOrFunction, f as isFunction, p as isPlainObject };//# sourceMappingURL=index.js.map