@lppedd/di-wise-neo 0.3.1 → 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 +84 -23
- package/dist/cjs/index.d.ts +115 -57
- package/dist/cjs/index.js +55 -26
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.d.mts +115 -57
- package/dist/es/index.mjs +54 -25
- package/dist/es/index.mjs.map +1 -1
- package/package.json +15 -19
package/README.md
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
<!--suppress HtmlDeprecatedAttribute -->
|
2
|
+
<h1 align="center">di-wise-neo</h1>
|
3
|
+
<p align="center">Lightweight, type-safe, flexible dependency injection library for TypeScript and JavaScript</p>
|
2
4
|
<div align="center">
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
5
|
+
|
6
|
+
[](https://github.com/lppedd/di-wise-neo/actions/workflows/test.yml)
|
7
|
+
[](https://www.npmjs.com/package/@lppedd/di-wise-neo)
|
8
|
+
[](https://bundlejs.com/?q=@lppedd/di-wise-neo)
|
9
|
+
[](https://github.com/lppedd/di-wise-neo/blob/main/LICENSE)
|
10
|
+
|
7
11
|
</div>
|
12
|
+
<img align="center" src="./.github/images/neo-wall.jpg" alt="di-wise-neo" style="border: 3px solid black; border-radius: 15px;" />
|
8
13
|
|
9
14
|
> [!NOTE]
|
10
15
|
>
|
@@ -16,12 +21,14 @@
|
|
16
21
|
|
17
22
|
- [Why yet another library](#why-yet-another-library)
|
18
23
|
- [Installation](#installation)
|
19
|
-
- [
|
24
|
+
- [API reference](#api-reference)
|
25
|
+
- [Ergonomics & Requirements](#ergonomics)
|
20
26
|
- [Quickstart](#quickstart)
|
21
27
|
- [Container scopes](#container-scopes)
|
22
28
|
- [Token registration](#token-registration)
|
23
29
|
- [Function-based injection](#function-based-injection)
|
24
30
|
- [Decorator-based injection](#decorator-based-injection)
|
31
|
+
- [Behavioral decorators](#behavioral-decorators)
|
25
32
|
- [Testing support](#testing-support)
|
26
33
|
|
27
34
|
## Why yet another library
|
@@ -75,7 +82,7 @@ production needs.
|
|
75
82
|
## Installation
|
76
83
|
|
77
84
|
```sh
|
78
|
-
npm
|
85
|
+
npm i @lppedd/di-wise-neo
|
79
86
|
```
|
80
87
|
|
81
88
|
```sh
|
@@ -86,12 +93,21 @@ pnpm add @lppedd/di-wise-neo
|
|
86
93
|
yarn add @lppedd/di-wise-neo
|
87
94
|
```
|
88
95
|
|
96
|
+
## API reference
|
97
|
+
|
98
|
+
You can find the complete API reference at [lppedd.github.io/di-wise-neo](https://lppedd.github.io/di-wise-neo)
|
99
|
+
|
89
100
|
## Ergonomics
|
90
101
|
|
91
102
|
- Does **not** depend on other libraries
|
92
103
|
- Does **not** use [reflect-metadata](https://www.npmjs.com/package/reflect-metadata) to drive decorators
|
93
104
|
- **Can** be used from JavaScript with function-based injection
|
94
105
|
|
106
|
+
### Requirements
|
107
|
+
|
108
|
+
- When using decorator-based injection, `experimentalDecorators` must be enabled in your `tsconfig.json` file
|
109
|
+
- The JavaScript environment must support features such as `Array.flat`, `WeakSet`, `WeakMap`, `Set`, and `Map`
|
110
|
+
|
95
111
|
## Quickstart
|
96
112
|
|
97
113
|
```ts
|
@@ -139,7 +155,7 @@ const container = createContainer({
|
|
139
155
|
defaultScope: Scope.Container,
|
140
156
|
});
|
141
157
|
|
142
|
-
// Register our managed dependencies
|
158
|
+
// Register our managed dependencies in the container
|
143
159
|
container.register(ExtensionContext)
|
144
160
|
.register(SecretStore)
|
145
161
|
.register(ContributionRegistrar);
|
@@ -209,21 +225,21 @@ Alternatively, use an explicit `ClassProvider` object - useful when registering
|
|
209
225
|
an interface or abstract type:
|
210
226
|
|
211
227
|
```ts
|
212
|
-
const
|
213
|
-
container.register(
|
228
|
+
const IStore = createType<Store>("Store");
|
229
|
+
container.register(IStore, {
|
214
230
|
useClass: SecretStore, // class SecretStore implements Store
|
215
231
|
});
|
216
232
|
```
|
217
233
|
|
218
|
-
Upon resolving `
|
219
|
-
caching it according to the configured scope.
|
234
|
+
Upon resolving `IStore` - which represents the `Store` interface - the container
|
235
|
+
creates an instance of `SecretStore`, caching it according to the configured scope.
|
220
236
|
|
221
237
|
### FactoryProvider
|
222
238
|
|
223
239
|
A lazily computed value can be registered using a factory function:
|
224
240
|
|
225
241
|
```ts
|
226
|
-
const Env =
|
242
|
+
const Env = createType<string>("Env")
|
227
243
|
container.register(Env, {
|
228
244
|
useFactory: () => isNode() ? "Node.js" : "browser",
|
229
245
|
});
|
@@ -234,10 +250,10 @@ according to the configured scope.
|
|
234
250
|
|
235
251
|
### ValueProvider
|
236
252
|
|
237
|
-
A
|
253
|
+
A fixed value - always taken as-is and unaffected by scopes - can be registered using:
|
238
254
|
|
239
255
|
```ts
|
240
|
-
const PID =
|
256
|
+
const PID = createType<number>("PID");
|
241
257
|
const processId = spawnProcess();
|
242
258
|
container.register(PID, {
|
243
259
|
useValue: processId,
|
@@ -253,7 +269,7 @@ Registers an alias to another token, allowing multiple identifiers to resolve to
|
|
253
269
|
Using the previous `PID` example, we can register a `TaskID` alias:
|
254
270
|
|
255
271
|
```ts
|
256
|
-
const TaskID =
|
272
|
+
const TaskID = createType<number>("TaskID");
|
257
273
|
container.register(TaskID, {
|
258
274
|
useExisting: PID,
|
259
275
|
});
|
@@ -299,7 +315,7 @@ never been registered in the container.
|
|
299
315
|
|
300
316
|
```ts
|
301
317
|
export class ExtensionContext {
|
302
|
-
readonly stores /*: Store[] */ = injectAll(
|
318
|
+
readonly stores /*: Store[] */ = injectAll(IStore);
|
303
319
|
|
304
320
|
/* ... */
|
305
321
|
|
@@ -330,7 +346,7 @@ has never been registered in the container.
|
|
330
346
|
```ts
|
331
347
|
export class ExtensionContext {
|
332
348
|
// The type does not change compared to injectAll(T), but the call does not fail
|
333
|
-
readonly stores /*: Store[] */ = optionalAll(
|
349
|
+
readonly stores /*: Store[] */ = optionalAll(IStore);
|
334
350
|
|
335
351
|
/* ... */
|
336
352
|
}
|
@@ -355,7 +371,7 @@ export class ProcessManager {
|
|
355
371
|
/* ... */
|
356
372
|
|
357
373
|
// The method is called immediately after instance construction
|
358
|
-
notifyListener(@Inject(ProcessListener)
|
374
|
+
notifyListener(@Inject(ProcessListener) listener: ProcessListener): void {
|
359
375
|
listener.processStarted(this.rootPID);
|
360
376
|
}
|
361
377
|
}
|
@@ -370,7 +386,7 @@ never been registered in the container.
|
|
370
386
|
|
371
387
|
```ts
|
372
388
|
export class ExtensionContext {
|
373
|
-
constructor(@InjectAll(
|
389
|
+
constructor(@InjectAll(IStore) readonly stores: Store[]) {}
|
374
390
|
|
375
391
|
/* ... */
|
376
392
|
|
@@ -401,7 +417,7 @@ has never been registered in the container.
|
|
401
417
|
```ts
|
402
418
|
export class ExtensionContext {
|
403
419
|
// The type does not change compared to @InjectAll, but construction does not fail
|
404
|
-
constructor(@OptionalAll(
|
420
|
+
constructor(@OptionalAll(IStore) readonly stores: Store[]) {}
|
405
421
|
|
406
422
|
/* ... */
|
407
423
|
}
|
@@ -412,22 +428,67 @@ export class ExtensionContext {
|
|
412
428
|
Sometimes you may need to reference a token or class that is declared later in the file.
|
413
429
|
Normally, attempting to do that would result in a `ReferenceError`:
|
414
430
|
|
415
|
-
> ReferenceError: Cannot access '
|
431
|
+
> ReferenceError: Cannot access 'IStore' before initialization
|
416
432
|
|
417
433
|
We can work around this problem by using the `forwardRef` helper function:
|
418
434
|
|
419
435
|
```ts
|
420
436
|
export class ExtensionContext {
|
421
|
-
constructor(@OptionalAll(forwardRef(() =>
|
437
|
+
constructor(@OptionalAll(forwardRef(() => IStore)) readonly stores: Store[]) {}
|
438
|
+
|
439
|
+
/* ... */
|
440
|
+
}
|
441
|
+
```
|
442
|
+
|
443
|
+
## Behavioral decorators
|
444
|
+
|
445
|
+
The library includes two behavioral decorators that influence how classes are registered in the container.
|
446
|
+
These decorators attach metadata to the class type, which is then interpreted by the container during registration.
|
422
447
|
|
448
|
+
### `@Scoped`
|
449
|
+
|
450
|
+
Specifies a default scope for the decorated class:
|
451
|
+
|
452
|
+
```ts
|
453
|
+
@Scoped(Scope.Container)
|
454
|
+
export class ExtensionContext {
|
423
455
|
/* ... */
|
424
456
|
}
|
425
457
|
```
|
426
458
|
|
459
|
+
Applying `@Scoped(Scope.Container)` to the `ExtensionContext` class instructs the DI container
|
460
|
+
to register it with the **Container** scope by default.
|
461
|
+
|
462
|
+
This default can be overridden by explicitly providing registration options:
|
463
|
+
|
464
|
+
```ts
|
465
|
+
container.register(
|
466
|
+
ExtensionContext,
|
467
|
+
{ useClass: ExtensionContext },
|
468
|
+
{ scope: Scope.Resolution },
|
469
|
+
);
|
470
|
+
```
|
471
|
+
|
472
|
+
In this example, `ExtensionContext` will be registered with **Resolution** scope instead.
|
473
|
+
|
474
|
+
### `@AutoRegister`
|
475
|
+
|
476
|
+
Enables automatic registration of the decorated class if it has not been registered explicitly.
|
477
|
+
|
478
|
+
```ts
|
479
|
+
@AutoRegister()
|
480
|
+
export class ExtensionContext {
|
481
|
+
/* ... */
|
482
|
+
}
|
483
|
+
|
484
|
+
// Resolve the class without prior registration. It works!
|
485
|
+
container.resolve(ExtensionContext);
|
486
|
+
```
|
487
|
+
|
427
488
|
## Testing support
|
428
489
|
|
429
490
|
Testing is an important part of software development, and dependency injection is meant to make it easier.
|
430
|
-
The
|
491
|
+
The container API exposes methods to more easily integrate with testing scenarios.
|
431
492
|
|
432
493
|
### `resetRegistry`
|
433
494
|
|
package/dist/cjs/index.d.ts
CHANGED
@@ -1,46 +1,30 @@
|
|
1
|
-
/**
|
2
|
-
* Constructor type.
|
3
|
-
*/
|
4
|
-
interface Constructor<Instance extends object> {
|
5
|
-
new (...args: any[]): Instance;
|
6
|
-
readonly name: string;
|
7
|
-
readonly length: number;
|
8
|
-
}
|
9
|
-
/**
|
10
|
-
* Token type.
|
11
|
-
*/
|
12
|
-
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value> : Type<Value>;
|
13
|
-
/**
|
14
|
-
* Describes a {@link Token} array with at least one element.
|
15
|
-
*/
|
16
|
-
type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];
|
17
1
|
/**
|
18
2
|
* Type API.
|
19
3
|
*/
|
20
4
|
interface Type<A> {
|
21
5
|
/**
|
22
|
-
*
|
6
|
+
* The name of the type.
|
23
7
|
*/
|
24
8
|
readonly name: string;
|
25
9
|
/**
|
26
|
-
*
|
10
|
+
* Creates an intersection type from another type.
|
27
11
|
*
|
28
12
|
* @example
|
29
13
|
* ```ts
|
30
|
-
* const A =
|
31
|
-
* const B =
|
14
|
+
* const A = createType<A>("A");
|
15
|
+
* const B = createType<B>("B");
|
32
16
|
*
|
33
17
|
* A.inter("I", B); // => Type<A & B>
|
34
18
|
* ```
|
35
19
|
*/
|
36
20
|
inter<B>(typeName: string, B: Type<B>): Type<A & B>;
|
37
21
|
/**
|
38
|
-
*
|
22
|
+
* Creates a union type from another type.
|
39
23
|
*
|
40
24
|
* @example
|
41
25
|
* ```ts
|
42
|
-
* const A =
|
43
|
-
* const B =
|
26
|
+
* const A = createType<A>("A");
|
27
|
+
* const B = createType<B>("B");
|
44
28
|
*
|
45
29
|
* A.union("U", B); // => Type<A | B>
|
46
30
|
* ```
|
@@ -48,16 +32,31 @@ interface Type<A> {
|
|
48
32
|
union<B>(typeName: string, B: Type<B>): Type<A | B>;
|
49
33
|
}
|
50
34
|
/**
|
51
|
-
*
|
35
|
+
* Constructor type.
|
36
|
+
*/
|
37
|
+
interface Constructor<Instance extends object> {
|
38
|
+
new (...args: any[]): Instance;
|
39
|
+
readonly name: string;
|
40
|
+
}
|
41
|
+
/**
|
42
|
+
* Token type.
|
43
|
+
*/
|
44
|
+
type Token<Value = any> = [Value] extends [object] ? Type<Value> | Constructor<Value> : Type<Value>;
|
45
|
+
/**
|
46
|
+
* Describes a {@link Token} array with at least one element.
|
47
|
+
*/
|
48
|
+
type Tokens<Value = any> = [Token<Value>, ...Token<Value>[]];
|
49
|
+
/**
|
50
|
+
* Creates a type token.
|
52
51
|
*
|
53
52
|
* @example
|
54
53
|
* ```ts
|
55
|
-
* const
|
54
|
+
* const ISpell = createType<Spell>("Spell");
|
56
55
|
* ```
|
57
56
|
*
|
58
57
|
* @__NO_SIDE_EFFECTS__
|
59
58
|
*/
|
60
|
-
declare function
|
59
|
+
declare function createType<T>(typeName: string): Type<T>;
|
61
60
|
|
62
61
|
/**
|
63
62
|
* Provides a class instance for a token via a class constructor.
|
@@ -65,31 +64,33 @@ declare function Type<T>(typeName: string): Type<T>;
|
|
65
64
|
interface ClassProvider<Instance extends object> {
|
66
65
|
readonly useClass: Constructor<Instance>;
|
67
66
|
}
|
68
|
-
/**
|
69
|
-
* Provides a value for a token via another existing token.
|
70
|
-
*/
|
71
|
-
interface ExistingProvider<Value> {
|
72
|
-
readonly useExisting: Token<Value>;
|
73
|
-
}
|
74
67
|
/**
|
75
68
|
* Provides a value for a token via a factory function.
|
76
69
|
*
|
77
|
-
* The factory function runs inside the injection context
|
78
|
-
*
|
70
|
+
* The factory function runs inside the injection context and can
|
71
|
+
* thus access dependencies via {@link inject}-like functions.
|
79
72
|
*/
|
80
73
|
interface FactoryProvider<Value> {
|
81
74
|
readonly useFactory: (...args: []) => Value;
|
82
75
|
}
|
83
76
|
/**
|
84
|
-
* Provides a
|
77
|
+
* Provides a static - already constructed - value for a token.
|
85
78
|
*/
|
86
79
|
interface ValueProvider<T> {
|
87
80
|
readonly useValue: T;
|
88
81
|
}
|
82
|
+
/**
|
83
|
+
* Aliases another registered token.
|
84
|
+
*
|
85
|
+
* Resolving this token will return the value of the aliased one.
|
86
|
+
*/
|
87
|
+
interface ExistingProvider<Value> {
|
88
|
+
readonly useExisting: Token<Value>;
|
89
|
+
}
|
89
90
|
/**
|
90
91
|
* A token provider.
|
91
92
|
*/
|
92
|
-
type Provider<Value = any> = ClassProvider<Value & object> |
|
93
|
+
type Provider<Value = any> = ClassProvider<Value & object> | FactoryProvider<Value> | ValueProvider<Value> | ExistingProvider<Value>;
|
93
94
|
|
94
95
|
declare const Scope: {
|
95
96
|
readonly Inherited: "Inherited";
|
@@ -115,7 +116,7 @@ interface RegistrationOptions {
|
|
115
116
|
* ```ts
|
116
117
|
* class Wizard {
|
117
118
|
* wand = inject(
|
118
|
-
*
|
119
|
+
* build(() => {
|
119
120
|
* const wand = inject(Wand);
|
120
121
|
* wand.owner = this;
|
121
122
|
* // ...
|
@@ -127,7 +128,7 @@ interface RegistrationOptions {
|
|
127
128
|
*
|
128
129
|
* @__NO_SIDE_EFFECTS__
|
129
130
|
*/
|
130
|
-
declare function
|
131
|
+
declare function build<Value>(factory: (...args: []) => Value): Type<Value>;
|
131
132
|
|
132
133
|
/**
|
133
134
|
* Container creation options.
|
@@ -212,35 +213,87 @@ interface Container {
|
|
212
213
|
* Returns whether the token is registered in this container or in parent containers, if any.
|
213
214
|
*/
|
214
215
|
isRegistered(token: Token): boolean;
|
216
|
+
/**
|
217
|
+
* Registers a concrete class, where the class acts as its own token.
|
218
|
+
*
|
219
|
+
* Tokens provided via the {@link Injectable} decorator applied to the class
|
220
|
+
* are also registered as aliases.
|
221
|
+
*
|
222
|
+
* The default registration scope is determined by the {@link Scoped} decorator,
|
223
|
+
* if present.
|
224
|
+
*/
|
225
|
+
registerClass<Instance extends object>(Class: Constructor<Instance>): void;
|
226
|
+
/**
|
227
|
+
* Registers a concrete class with a token.
|
228
|
+
*
|
229
|
+
* The default registration scope is determined by the {@link Scoped} decorator
|
230
|
+
* applied to the class, if present, but it can be overridden by passing explicit
|
231
|
+
* registration options.
|
232
|
+
*/
|
233
|
+
registerClass<Instance extends object, ProvidedInstance extends Instance>(token: Token<Instance>, Class: Constructor<ProvidedInstance>, options?: RegistrationOptions): void;
|
234
|
+
/**
|
235
|
+
* Registers a token whose value is produced by a factory function.
|
236
|
+
*
|
237
|
+
* The factory function runs inside the injection context and can
|
238
|
+
* thus access dependencies via {@link inject}-like functions.
|
239
|
+
*/
|
240
|
+
registerFactory<Value, ProvidedValue extends Value>(token: Token<Value>, factory: (...args: []) => ProvidedValue, options?: RegistrationOptions): void;
|
241
|
+
/**
|
242
|
+
* Registers a token with a fixed value.
|
243
|
+
*
|
244
|
+
* The provided value is returned as-is when the token is resolved (scopes do not apply).
|
245
|
+
*/
|
246
|
+
registerValue<Value, ProvidedValue extends Value>(token: Token<Value>, value: ProvidedValue): void;
|
247
|
+
/**
|
248
|
+
* Registers one or more tokens as aliases for a target token.
|
249
|
+
*
|
250
|
+
* When an alias is resolved, the target token is resolved instead.
|
251
|
+
*/
|
252
|
+
registerAlias<Value, ProvidedValue extends Value>(targetToken: Token<ProvidedValue>, aliasTokens: Tokens<Value>): void;
|
215
253
|
/**
|
216
254
|
* Registers a {@link ClassProvider}, using the class itself as its token.
|
217
255
|
*
|
218
|
-
* Tokens provided
|
219
|
-
* are also registered as aliases.
|
220
|
-
*
|
256
|
+
* Tokens provided via the {@link Injectable} decorator applied to the class
|
257
|
+
* are also registered as aliases.
|
258
|
+
*
|
259
|
+
* The scope is determined by the {@link Scoped} decorator, if present.
|
260
|
+
*
|
261
|
+
* @see registerClass
|
221
262
|
*/
|
222
|
-
register<Instance extends object>(Class: Constructor<Instance>):
|
263
|
+
register<Instance extends object>(Class: Constructor<Instance>): Container;
|
223
264
|
/**
|
224
265
|
* Registers a {@link ClassProvider} with a token.
|
266
|
+
*
|
267
|
+
* The default registration scope is determined by the {@link Scoped} decorator
|
268
|
+
* applied to the provided class, if present, but it can be overridden by
|
269
|
+
* passing explicit registration options.
|
270
|
+
*
|
271
|
+
* @see registerClass
|
225
272
|
*/
|
226
|
-
register<Instance extends object, ProviderInstance extends Instance>(token: Token<Instance>, provider: ClassProvider<ProviderInstance>, options?: RegistrationOptions):
|
273
|
+
register<Instance extends object, ProviderInstance extends Instance>(token: Token<Instance>, provider: ClassProvider<ProviderInstance>, options?: RegistrationOptions): Container;
|
227
274
|
/**
|
228
275
|
* Registers a {@link FactoryProvider} with a token.
|
276
|
+
*
|
277
|
+
* @see registerFactory
|
229
278
|
*/
|
230
|
-
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: FactoryProvider<ProviderValue>, options?: RegistrationOptions):
|
279
|
+
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: FactoryProvider<ProviderValue>, options?: RegistrationOptions): Container;
|
231
280
|
/**
|
232
281
|
* Registers an {@link ExistingProvider} with a token.
|
233
282
|
*
|
234
283
|
* The token will alias the one set in `useExisting`.
|
284
|
+
*
|
285
|
+
* @see registerAlias
|
235
286
|
*/
|
236
|
-
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ExistingProvider<ProviderValue>):
|
287
|
+
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ExistingProvider<ProviderValue>): Container;
|
237
288
|
/**
|
238
289
|
* Registers a {@link ValueProvider} with a token.
|
239
290
|
*
|
240
291
|
* Values provided via `useValue` are never cached (scopes do not apply)
|
241
292
|
* and are simply returned as-is.
|
293
|
+
*
|
294
|
+
* @see registerValue
|
242
295
|
*/
|
243
|
-
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ValueProvider<ProviderValue>):
|
296
|
+
register<Value, ProviderValue extends Value>(token: Token<Value>, provider: ValueProvider<ProviderValue>): Container;
|
244
297
|
/**
|
245
298
|
* Removes all registrations for the given token from the container's internal registry.
|
246
299
|
*
|
@@ -364,8 +417,8 @@ interface Container {
|
|
364
417
|
declare function createContainer(options?: Partial<ContainerOptions>): Container;
|
365
418
|
|
366
419
|
/**
|
367
|
-
* Class decorator
|
368
|
-
* when first
|
420
|
+
* Class decorator that enables auto-registration of an unregistered class,
|
421
|
+
* when the class is first resolved from the container.
|
369
422
|
*
|
370
423
|
* @example
|
371
424
|
* ```ts
|
@@ -387,9 +440,14 @@ interface TokenRef<Value = any> {
|
|
387
440
|
readonly getRefToken: () => Token<Value>;
|
388
441
|
}
|
389
442
|
/**
|
390
|
-
* Allows referencing
|
443
|
+
* Allows referencing tokens that are declared later in the file by wrapping them
|
444
|
+
* in a lazily evaluated function.
|
391
445
|
*/
|
392
446
|
declare function forwardRef<Value>(token: () => Tokens<Value>): TokensRef<Value>;
|
447
|
+
/**
|
448
|
+
* Allows referencing a token that is declared later in the file by wrapping it
|
449
|
+
* in a lazily evaluated function.
|
450
|
+
*/
|
393
451
|
declare function forwardRef<Value>(token: () => Token<Value>): TokenRef<Value>;
|
394
452
|
|
395
453
|
/**
|
@@ -424,8 +482,8 @@ declare function Inject<Value>(token: Token<Value>): ParameterDecorator;
|
|
424
482
|
declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
|
425
483
|
|
426
484
|
/**
|
427
|
-
* Class decorator
|
428
|
-
* when
|
485
|
+
* Class decorator that registers additional aliasing tokens for the decorated type,
|
486
|
+
* when the type is first registered in the container.
|
429
487
|
*
|
430
488
|
* The container uses {@link ExistingProvider} under the hood.
|
431
489
|
*
|
@@ -437,8 +495,8 @@ declare function Inject<Value>(tokens: TokenRef<Value>): ParameterDecorator;
|
|
437
495
|
*/
|
438
496
|
declare function Injectable<This extends object, Value extends This>(...tokens: Tokens<Value>): ClassDecorator;
|
439
497
|
/**
|
440
|
-
* Class decorator
|
441
|
-
* when
|
498
|
+
* Class decorator that registers additional aliasing tokens for the decorated type,
|
499
|
+
* when the type is first registered in the container.
|
442
500
|
*
|
443
501
|
* The container uses {@link ExistingProvider} under the hood.
|
444
502
|
*
|
@@ -718,7 +776,7 @@ declare const Injector: Type<Injector>;
|
|
718
776
|
*/
|
719
777
|
interface MiddlewareComposer {
|
720
778
|
/**
|
721
|
-
*
|
779
|
+
* Adds a middleware function to the composer.
|
722
780
|
*/
|
723
781
|
use<MethodKey extends keyof Container>(key: MethodKey, wrap: Container[MethodKey] extends Function ? (next: Container[MethodKey]) => Container[MethodKey] : never): MiddlewareComposer;
|
724
782
|
}
|
@@ -744,7 +802,7 @@ interface Middleware {
|
|
744
802
|
(composer: MiddlewareComposer, api: Readonly<Container>): void;
|
745
803
|
}
|
746
804
|
/**
|
747
|
-
*
|
805
|
+
* Applies middleware functions to a container.
|
748
806
|
*
|
749
807
|
* Middlewares are applied in array order, but execute in reverse order.
|
750
808
|
*
|
@@ -768,5 +826,5 @@ interface Middleware {
|
|
768
826
|
*/
|
769
827
|
declare function applyMiddleware(container: Container, middlewares: Middleware[]): Container;
|
770
828
|
|
771
|
-
export { AutoRegister,
|
772
|
-
export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, ValueProvider };
|
829
|
+
export { AutoRegister, Inject, InjectAll, Injectable, Injector, Optional, OptionalAll, Scope, Scoped, applyMiddleware, build, createContainer, createType, forwardRef, inject, injectAll, injectBy };
|
830
|
+
export type { ClassProvider, Constructor, Container, ContainerOptions, ExistingProvider, FactoryProvider, Middleware, MiddlewareComposer, Provider, RegistrationOptions, Token, TokenRef, Tokens, TokensRef, Type, ValueProvider };
|