@art-ws/di 2.0.18 → 2.0.19

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.
@@ -23,6 +23,8 @@ export declare class Injector {
23
23
  injector: Injector;
24
24
  }) => void;
25
25
  }>): Promise<T>;
26
+ dispose(): void;
27
+ getInstances(): unknown[];
26
28
  }
27
29
  export declare function inject<T>(token: Token<T>): T;
28
30
  export declare function getRootInjector(): Injector;
@@ -112,7 +112,7 @@ export class Injector {
112
112
  async runScope(fn, options) {
113
113
  const injector = new Injector();
114
114
  injector.parent = this;
115
- injector.addProviders(...(options?.providers || []));
115
+ injector.addProviders({ token: Injector, factory: () => injector }, ...(options?.providers || []));
116
116
  Injector.onScope?.({ injector });
117
117
  return asyncLocalStorage.run({ injector }, async () => {
118
118
  try {
@@ -123,6 +123,14 @@ export class Injector {
123
123
  }
124
124
  });
125
125
  }
126
+ dispose() {
127
+ this.parent = null;
128
+ this.#instances.clear();
129
+ this.#factories.clear();
130
+ }
131
+ getInstances() {
132
+ return Array.from(this.#instances.values());
133
+ }
126
134
  }
127
135
  export function inject(token) {
128
136
  const asyncContext = asyncLocalStorage.getStore();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@art-ws/di",
3
- "version": "2.0.18",
3
+ "version": "2.0.19",
4
4
  "description": "Dependency injection for TypeScript",
5
5
  "license": "UNLICENSED",
6
6
  "author": "art-ws Team",