@art-ws/di 2.0.17 → 2.0.18

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.
@@ -25,3 +25,7 @@ export declare class Injector {
25
25
  }>): Promise<T>;
26
26
  }
27
27
  export declare function inject<T>(token: Token<T>): T;
28
+ export declare function getRootInjector(): Injector;
29
+ export declare function setRootInjector(injector: Injector | undefined): void;
30
+ export declare function getOnScopeHandler(): OnScopeHandler | undefined;
31
+ export declare function setOnScopeHandler(handler: OnScopeHandler | undefined): void;
@@ -4,19 +4,16 @@ const asyncLocalStorage = new AsyncLocalStorage();
4
4
  const rootState = {};
5
5
  export class Injector {
6
6
  static get root() {
7
- if (!rootState.injector) {
8
- throw new Error(`Root injector is not initialized`);
9
- }
10
- return rootState.injector;
7
+ return getRootInjector();
11
8
  }
12
9
  static set root(value) {
13
- rootState.injector = value;
10
+ setRootInjector(value);
14
11
  }
15
12
  static get onScope() {
16
- return rootState.onScope;
13
+ return getOnScopeHandler();
17
14
  }
18
15
  static set onScope(value) {
19
- rootState.onScope = value;
16
+ setOnScopeHandler(value);
20
17
  }
21
18
  parent = null;
22
19
  #instances = new Map();
@@ -134,6 +131,21 @@ export function inject(token) {
134
131
  throw new Error(`No injector found`);
135
132
  return injector.get(token);
136
133
  }
134
+ export function getRootInjector() {
135
+ if (!rootState.injector) {
136
+ throw new Error(`Root injector is not initialized`);
137
+ }
138
+ return rootState.injector;
139
+ }
140
+ export function setRootInjector(injector) {
141
+ rootState.injector = injector;
142
+ }
143
+ export function getOnScopeHandler() {
144
+ return rootState.onScope;
145
+ }
146
+ export function setOnScopeHandler(handler) {
147
+ rootState.onScope = handler;
148
+ }
137
149
  function isClass(value) {
138
150
  return typeof value === "function" && !!value.prototype;
139
151
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@art-ws/di",
3
- "version": "2.0.17",
3
+ "version": "2.0.18",
4
4
  "description": "Dependency injection for TypeScript",
5
5
  "license": "UNLICENSED",
6
6
  "author": "art-ws Team",