@tsed/di 8.18.2 → 8.19.1
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/lib/esm/common/decorators/autoInjectable.js +28 -9
- package/lib/esm/common/decorators/constant.js +26 -22
- package/lib/esm/common/decorators/controller.js +40 -20
- package/lib/esm/common/decorators/injectable.js +30 -10
- package/lib/esm/common/decorators/intercept.js +41 -3
- package/lib/esm/common/decorators/interceptor.js +31 -4
- package/lib/esm/common/decorators/module.js +36 -5
- package/lib/esm/common/decorators/opts.js +20 -12
- package/lib/esm/common/decorators/overrideProvider.js +38 -4
- package/lib/esm/common/decorators/scope.js +32 -3
- package/lib/esm/common/decorators/service.js +24 -4
- package/lib/esm/common/decorators/useOpts.js +21 -13
- package/lib/esm/common/decorators/value.js +28 -22
- package/lib/esm/common/domain/Container.js +20 -0
- package/lib/esm/common/domain/ContextLogger.js +21 -0
- package/lib/esm/common/domain/ControllerProvider.js +22 -0
- package/lib/esm/common/domain/DIContext.js +22 -0
- package/lib/esm/common/domain/InjectablePropertyType.js +16 -0
- package/lib/esm/common/domain/LocalsContainer.js +21 -0
- package/lib/esm/common/domain/Provider.js +19 -0
- package/lib/esm/common/domain/ProviderScope.js +25 -0
- package/lib/esm/common/domain/ProviderType.js +25 -0
- package/lib/esm/common/errors/InjectionError.js +24 -0
- package/lib/esm/common/errors/InvalidPropertyTokenError.js +15 -0
- package/lib/esm/common/fn/inject.js +19 -6
- package/lib/esm/common/fn/injectMany.js +24 -6
- package/lib/esm/common/fn/injectable.js +57 -0
- package/lib/esm/common/fn/injector.js +21 -2
- package/lib/esm/common/fn/lazyInject.js +48 -1
- package/lib/esm/common/fn/localsContainer.js +31 -2
- package/lib/esm/common/fn/logger.js +15 -1
- package/lib/esm/common/services/DIConfiguration.js +24 -0
- package/lib/esm/common/services/DILogger.js +23 -0
- package/lib/esm/common/services/InjectorService.js +89 -43
- package/lib/types/common/decorators/autoInjectable.d.ts +31 -10
- package/lib/types/common/decorators/configuration.d.ts +32 -2
- package/lib/types/common/decorators/constant.d.ts +26 -22
- package/lib/types/common/decorators/controller.d.ts +40 -20
- package/lib/types/common/decorators/inject.d.ts +29 -7
- package/lib/types/common/decorators/injectable.d.ts +30 -10
- package/lib/types/common/decorators/intercept.d.ts +41 -3
- package/lib/types/common/decorators/interceptor.d.ts +31 -4
- package/lib/types/common/decorators/lazyInject.d.ts +43 -9
- package/lib/types/common/decorators/module.d.ts +36 -5
- package/lib/types/common/decorators/opts.d.ts +20 -12
- package/lib/types/common/decorators/overrideProvider.d.ts +38 -4
- package/lib/types/common/decorators/scope.d.ts +32 -3
- package/lib/types/common/decorators/service.d.ts +24 -4
- package/lib/types/common/decorators/useOpts.d.ts +21 -13
- package/lib/types/common/decorators/value.d.ts +28 -22
- package/lib/types/common/domain/Container.d.ts +20 -0
- package/lib/types/common/domain/ContextLogger.d.ts +26 -0
- package/lib/types/common/domain/ControllerProvider.d.ts +29 -0
- package/lib/types/common/domain/DIContext.d.ts +27 -0
- package/lib/types/common/domain/InjectablePropertyType.d.ts +16 -0
- package/lib/types/common/domain/LocalsContainer.d.ts +21 -0
- package/lib/types/common/domain/Provider.d.ts +25 -0
- package/lib/types/common/domain/ProviderScope.d.ts +25 -0
- package/lib/types/common/domain/ProviderType.d.ts +25 -0
- package/lib/types/common/errors/InjectionError.d.ts +24 -0
- package/lib/types/common/errors/InvalidPropertyTokenError.d.ts +15 -0
- package/lib/types/common/fn/configuration.d.ts +31 -0
- package/lib/types/common/fn/constant.d.ts +22 -0
- package/lib/types/common/fn/inject.d.ts +19 -6
- package/lib/types/common/fn/injectMany.d.ts +24 -6
- package/lib/types/common/fn/injectable.d.ts +57 -0
- package/lib/types/common/fn/injector.d.ts +21 -2
- package/lib/types/common/fn/lazyInject.d.ts +48 -1
- package/lib/types/common/fn/localsContainer.d.ts +31 -2
- package/lib/types/common/fn/logger.d.ts +15 -1
- package/lib/types/common/fn/refValue.d.ts +15 -6
- package/lib/types/common/interfaces/AlterRunInContext.d.ts +26 -0
- package/lib/types/common/interfaces/DILogger.d.ts +36 -0
- package/lib/types/common/interfaces/DILoggerOptions.d.ts +23 -0
- package/lib/types/common/interfaces/ImportTokenProviderOpts.d.ts +43 -0
- package/lib/types/common/interfaces/InterceptorContext.d.ts +35 -0
- package/lib/types/common/interfaces/InterceptorMethods.d.ts +27 -0
- package/lib/types/common/interfaces/InvokeOptions.d.ts +8 -0
- package/lib/types/common/interfaces/OnDestroy.d.ts +22 -0
- package/lib/types/common/interfaces/OnInit.d.ts +22 -0
- package/lib/types/common/interfaces/ProviderOpts.d.ts +31 -0
- package/lib/types/common/interfaces/ResolvedInvokeOptions.d.ts +9 -0
- package/lib/types/common/interfaces/TokenProvider.d.ts +32 -2
- package/lib/types/common/interfaces/TokenRoute.d.ts +16 -0
- package/lib/types/common/services/DIConfiguration.d.ts +24 -0
- package/lib/types/common/services/DILogger.d.ts +28 -0
- package/lib/types/common/services/InjectorService.d.ts +89 -43
- package/lib/types/node/utils/asyncHookContext.d.ts +0 -1
- package/package.json +6 -6
|
@@ -5,24 +5,28 @@ import type { InvokeOptions } from "../interfaces/InvokeOptions.js";
|
|
|
5
5
|
import type { TokenProvider } from "../interfaces/TokenProvider.js";
|
|
6
6
|
import { DIConfiguration } from "./DIConfiguration.js";
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Core dependency injection orchestrator managing provider lifecycle and resolution.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
10
|
+
* The main service responsible for registering, resolving, and managing all injectable providers.
|
|
11
|
+
* Handles dependency graph resolution, instance caching, scope management, and lifecycle hooks.
|
|
12
|
+
*
|
|
13
|
+
* ### Usage
|
|
11
14
|
*
|
|
12
15
|
* ```typescript
|
|
13
16
|
* import {InjectorService} from "@tsed/di";
|
|
14
17
|
*
|
|
15
|
-
* // Import the services (all services are decorated with @Service()
|
|
18
|
+
* // Import the services (all services are decorated with @Service())
|
|
16
19
|
* import MyService1 from "./services/service1.js";
|
|
17
20
|
* import MyService2 from "./services/service2.js";
|
|
18
21
|
* import MyService3 from "./services/service3.js";
|
|
19
22
|
*
|
|
20
|
-
* // When all services are imported, you can load InjectorService
|
|
21
|
-
*
|
|
23
|
+
* // When all services are imported, you can load InjectorService
|
|
22
24
|
* await injector().load();
|
|
23
25
|
*
|
|
24
26
|
* const myService1 = injector.get<MyService1>(MyService1);
|
|
25
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @public
|
|
26
30
|
*/
|
|
27
31
|
export declare class InjectorService extends Container {
|
|
28
32
|
#private;
|
|
@@ -32,105 +36,147 @@ export declare class InjectorService extends Container {
|
|
|
32
36
|
constructor();
|
|
33
37
|
isLoaded(): boolean;
|
|
34
38
|
/**
|
|
35
|
-
* Return a list of
|
|
39
|
+
* Return a list of all instances built by the injector.
|
|
40
|
+
*
|
|
41
|
+
* @returns An array of all cached provider instances
|
|
36
42
|
*/
|
|
37
43
|
toArray(): any[];
|
|
38
44
|
/**
|
|
39
|
-
* Get a service or factory already constructed from
|
|
45
|
+
* Get a service or factory already constructed from its symbol or class.
|
|
40
46
|
*
|
|
41
|
-
*
|
|
47
|
+
* Returns the cached instance if available, otherwise resolves and caches the provider.
|
|
48
|
+
*
|
|
49
|
+
* ### Usage
|
|
42
50
|
*
|
|
43
51
|
* ```typescript
|
|
44
52
|
* import {InjectorService} from "@tsed/di";
|
|
45
53
|
* import MyService from "./services.js";
|
|
46
54
|
*
|
|
47
55
|
* class OtherService {
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
56
|
+
* constructor(injectorService: InjectorService) {
|
|
57
|
+
* const myService = injectorService.get<MyService>(MyService);
|
|
58
|
+
* }
|
|
51
59
|
* }
|
|
52
60
|
* ```
|
|
53
61
|
*
|
|
54
|
-
* @param token The class or symbol registered in InjectorService
|
|
55
|
-
* @param options
|
|
62
|
+
* @param token The class or symbol registered in InjectorService
|
|
63
|
+
* @param options Optional invocation options
|
|
64
|
+
* @returns The resolved provider instance
|
|
56
65
|
*/
|
|
57
66
|
get<T = any>(token: TokenProvider<T>, options?: Partial<InvokeOptions>): T;
|
|
58
67
|
/**
|
|
59
|
-
* Return all
|
|
68
|
+
* Return all instances of providers matching the specified type.
|
|
69
|
+
*
|
|
70
|
+
* Retrieves all providers of a given type and resolves their instances.
|
|
71
|
+
*
|
|
72
|
+
* @param type The provider type to filter by (e.g., ProviderType.CONTROLLER)
|
|
73
|
+
* @param options Optional invocation options
|
|
74
|
+
* @returns Array of resolved instances matching the type
|
|
60
75
|
*/
|
|
61
76
|
getMany<Type = any>(type: any, options?: Partial<InvokeOptions>): Type[];
|
|
62
77
|
/**
|
|
63
|
-
*
|
|
78
|
+
* Check if a provider instance exists in the cache.
|
|
79
|
+
*
|
|
80
|
+
* @param token The token to check for
|
|
81
|
+
* @returns `true` if the instance is cached, `false` otherwise
|
|
64
82
|
*/
|
|
65
83
|
has(token: TokenProvider): boolean;
|
|
66
84
|
/**
|
|
67
|
-
*
|
|
85
|
+
* Create an alias for a provider token.
|
|
86
|
+
*
|
|
87
|
+
* Allows the same provider instance to be retrieved using a different token.
|
|
88
|
+
*
|
|
89
|
+
* @param token The original provider token
|
|
90
|
+
* @param alias The alias token to register
|
|
91
|
+
* @returns The injector instance for chaining
|
|
68
92
|
*/
|
|
69
93
|
alias(token: TokenProvider, alias: TokenProvider): this;
|
|
70
94
|
/**
|
|
71
|
-
* Resolve
|
|
95
|
+
* Resolve a provider token and return its instance.
|
|
72
96
|
*
|
|
73
|
-
* If the token isn't cached, the injector
|
|
97
|
+
* If the token isn't cached, the injector creates the instance according to the provider configuration
|
|
98
|
+
* and caches it based on the provider's scope (singleton, request, or instance).
|
|
74
99
|
*
|
|
75
|
-
*
|
|
100
|
+
* ### Usage
|
|
76
101
|
*
|
|
77
102
|
* ```typescript
|
|
78
103
|
* import {InjectorService} from "@tsed/di";
|
|
79
104
|
* import MyService from "./services.js";
|
|
80
105
|
*
|
|
81
106
|
* class OtherService {
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
107
|
+
* constructor(injectorService: InjectorService) {
|
|
108
|
+
* const myService = injectorService.resolve<MyService>(MyService);
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
86
111
|
* ```
|
|
87
112
|
*
|
|
88
|
-
* @param token The injectable class to invoke.
|
|
89
|
-
* @param options
|
|
90
|
-
* @returns
|
|
113
|
+
* @param token The injectable class to invoke. Constructor parameters are injected automatically
|
|
114
|
+
* @param options Optional invocation options (locals, rebuild, useOpts, etc.)
|
|
115
|
+
* @returns The resolved provider instance
|
|
91
116
|
*/
|
|
92
117
|
resolve<Type = any>(token: TokenProvider<Type>, options?: Partial<InvokeOptions>): Type;
|
|
93
118
|
/**
|
|
94
|
-
*
|
|
119
|
+
* Invoke a provider token and return its instance.
|
|
95
120
|
*
|
|
96
|
-
* If the token isn't cached, the injector
|
|
121
|
+
* Alias for `resolve()`. If the token isn't cached, the injector creates the instance
|
|
122
|
+
* according to the provider configuration.
|
|
97
123
|
*
|
|
98
|
-
*
|
|
124
|
+
* ### Usage
|
|
99
125
|
*
|
|
100
126
|
* ```typescript
|
|
101
127
|
* import {InjectorService} from "@tsed/di";
|
|
102
128
|
* import MyService from "./services.js";
|
|
103
129
|
*
|
|
104
130
|
* class OtherService {
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
131
|
+
* constructor(injectorService: InjectorService) {
|
|
132
|
+
* const myService = injectorService.invoke<MyService>(MyService);
|
|
133
|
+
* }
|
|
134
|
+
* }
|
|
109
135
|
* ```
|
|
110
136
|
*
|
|
111
|
-
* @param token The injectable class to invoke.
|
|
112
|
-
* @param options
|
|
113
|
-
* @returns
|
|
114
|
-
* @
|
|
137
|
+
* @param token The injectable class to invoke. Constructor parameters are injected automatically
|
|
138
|
+
* @param options Optional invocation options (locals, rebuild, useOpts, etc.)
|
|
139
|
+
* @returns The resolved provider instance
|
|
140
|
+
* @see resolve
|
|
115
141
|
*/
|
|
116
142
|
invoke<Type = any>(token: TokenProvider<Type>, options?: Partial<InvokeOptions>): Type;
|
|
117
143
|
/**
|
|
118
|
-
* Build
|
|
144
|
+
* Build all asynchronous providers.
|
|
145
|
+
*
|
|
146
|
+
* Resolves providers that have async factories or async initialization.
|
|
147
|
+
* Called automatically during the `load()` process.
|
|
119
148
|
*/
|
|
120
149
|
loadAsync(): Promise<void>;
|
|
121
150
|
/**
|
|
122
|
-
* Build
|
|
151
|
+
* Build all synchronous singleton providers.
|
|
152
|
+
*
|
|
153
|
+
* Instantiates all singleton-scoped providers that haven't been cached yet.
|
|
154
|
+
* Called automatically during the `load()` process after async providers.
|
|
123
155
|
*/
|
|
124
156
|
loadSync(): void;
|
|
125
157
|
/**
|
|
126
|
-
*
|
|
158
|
+
* Load and initialize all registered providers.
|
|
127
159
|
*
|
|
128
|
-
*
|
|
160
|
+
* Bootstraps the DI system by resolving configuration, building provider instances,
|
|
161
|
+
* and triggering lifecycle hooks (`$beforeInit`, `$onInit`).
|
|
162
|
+
*
|
|
163
|
+
* ### Usage
|
|
164
|
+
*
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import {injector} from "@tsed/di";
|
|
167
|
+
*
|
|
168
|
+
* await injector().load();
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @param container Optional container with additional providers to merge
|
|
129
172
|
*/
|
|
130
173
|
load(container?: Container): Promise<void>;
|
|
131
174
|
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
175
|
+
* Resolve and merge all provider configurations.
|
|
176
|
+
*
|
|
177
|
+
* Collects configuration from all providers decorated with `@Configuration`,
|
|
178
|
+
* merges them, and stores the result in the injector settings.
|
|
179
|
+
* Called automatically during the load process.
|
|
134
180
|
*/
|
|
135
181
|
resolveConfiguration(): Promise<void>;
|
|
136
182
|
/**
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/di",
|
|
3
3
|
"description": "DI module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.
|
|
5
|
+
"version": "8.19.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -29,14 +29,14 @@
|
|
|
29
29
|
"uuid": "^10.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@tsed/barrels": "8.
|
|
33
|
-
"@tsed/core": "8.
|
|
34
|
-
"@tsed/hooks": "8.
|
|
32
|
+
"@tsed/barrels": "8.19.1",
|
|
33
|
+
"@tsed/core": "8.19.1",
|
|
34
|
+
"@tsed/hooks": "8.19.1",
|
|
35
35
|
"@tsed/logger": "^8.0.0",
|
|
36
|
-
"@tsed/typescript": "8.
|
|
36
|
+
"@tsed/typescript": "8.19.1",
|
|
37
37
|
"cross-env": "7.0.3",
|
|
38
38
|
"eslint": "9.12.0",
|
|
39
|
-
"typescript": "5.
|
|
39
|
+
"typescript": "5.9.3",
|
|
40
40
|
"vite": "7.1.11",
|
|
41
41
|
"vitest": "3.2.4"
|
|
42
42
|
},
|