ts-ioc-container 60.1.0 → 60.2.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/cjm/container/Container.js +11 -1
- package/cjm/container/EmptyContainer.js +3 -0
- package/esm/container/Container.js +11 -1
- package/esm/container/EmptyContainer.js +3 -0
- package/package.json +1 -1
- package/typings/container/Container.d.ts +3 -1
- package/typings/container/EmptyContainer.d.ts +2 -1
- package/typings/container/IContainer.d.ts +2 -0
- package/typings/index.d.ts +1 -1
|
@@ -22,6 +22,7 @@ class Container {
|
|
|
22
22
|
onConstructHookList = [];
|
|
23
23
|
onDisposeHookList = [];
|
|
24
24
|
onScopeCreatedHookList = [];
|
|
25
|
+
onProviderRegisteredHookList = [];
|
|
25
26
|
constructor(options = {}) {
|
|
26
27
|
this.injector = options.injector ?? new MetadataInjector_1.MetadataInjector();
|
|
27
28
|
this.parent = options.parent ?? new EmptyContainer_1.EmptyContainer();
|
|
@@ -31,6 +32,9 @@ class Container {
|
|
|
31
32
|
this.validateContainer();
|
|
32
33
|
this.providers.set(key, provider);
|
|
33
34
|
this.aliases.setAliasesByKey(key, aliases);
|
|
35
|
+
for (const onProviderRegistered of this.onProviderRegisteredHookList) {
|
|
36
|
+
onProviderRegistered(provider, key, this);
|
|
37
|
+
}
|
|
34
38
|
return this;
|
|
35
39
|
}
|
|
36
40
|
resolve(target, { args = [], child = this, lazy } = {}) {
|
|
@@ -76,7 +80,8 @@ class Container {
|
|
|
76
80
|
const scope = new Container({ injector: this.injector, parent: this, tags })
|
|
77
81
|
.onConstruct(...this.onConstructHookList)
|
|
78
82
|
.onInstanceDisposed(...this.onDisposeHookList)
|
|
79
|
-
.onScopeCreated(...this.onScopeCreatedHookList)
|
|
83
|
+
.onScopeCreated(...this.onScopeCreatedHookList)
|
|
84
|
+
.onProviderRegistered(...this.onProviderRegisteredHookList);
|
|
80
85
|
for (const registration of this.getRegistrations()) {
|
|
81
86
|
registration.applyTo(scope);
|
|
82
87
|
}
|
|
@@ -113,6 +118,7 @@ class Container {
|
|
|
113
118
|
this.onConstructHookList.length = 0;
|
|
114
119
|
this.onDisposeHookList.length = 0;
|
|
115
120
|
this.onScopeCreatedHookList.length = 0;
|
|
121
|
+
this.onProviderRegisteredHookList.length = 0;
|
|
116
122
|
}
|
|
117
123
|
addRegistration(registration) {
|
|
118
124
|
this.registrations.push(registration);
|
|
@@ -137,6 +143,10 @@ class Container {
|
|
|
137
143
|
this.onScopeCreatedHookList.push(...hooks);
|
|
138
144
|
return this;
|
|
139
145
|
}
|
|
146
|
+
onProviderRegistered(...hooks) {
|
|
147
|
+
this.onProviderRegisteredHookList.push(...hooks);
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
140
150
|
addInstance(instance) {
|
|
141
151
|
this.instances.add(instance);
|
|
142
152
|
for (const onConstruct of this.onConstructHookList) {
|
|
@@ -69,5 +69,8 @@ class EmptyContainer {
|
|
|
69
69
|
onScopeCreated(...hooks) {
|
|
70
70
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
71
71
|
}
|
|
72
|
+
onProviderRegistered(...hooks) {
|
|
73
|
+
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
exports.EmptyContainer = EmptyContainer;
|
|
@@ -19,6 +19,7 @@ export class Container {
|
|
|
19
19
|
onConstructHookList = [];
|
|
20
20
|
onDisposeHookList = [];
|
|
21
21
|
onScopeCreatedHookList = [];
|
|
22
|
+
onProviderRegisteredHookList = [];
|
|
22
23
|
constructor(options = {}) {
|
|
23
24
|
this.injector = options.injector ?? new MetadataInjector();
|
|
24
25
|
this.parent = options.parent ?? new EmptyContainer();
|
|
@@ -28,6 +29,9 @@ export class Container {
|
|
|
28
29
|
this.validateContainer();
|
|
29
30
|
this.providers.set(key, provider);
|
|
30
31
|
this.aliases.setAliasesByKey(key, aliases);
|
|
32
|
+
for (const onProviderRegistered of this.onProviderRegisteredHookList) {
|
|
33
|
+
onProviderRegistered(provider, key, this);
|
|
34
|
+
}
|
|
31
35
|
return this;
|
|
32
36
|
}
|
|
33
37
|
resolve(target, { args = [], child = this, lazy } = {}) {
|
|
@@ -73,7 +77,8 @@ export class Container {
|
|
|
73
77
|
const scope = new Container({ injector: this.injector, parent: this, tags })
|
|
74
78
|
.onConstruct(...this.onConstructHookList)
|
|
75
79
|
.onInstanceDisposed(...this.onDisposeHookList)
|
|
76
|
-
.onScopeCreated(...this.onScopeCreatedHookList)
|
|
80
|
+
.onScopeCreated(...this.onScopeCreatedHookList)
|
|
81
|
+
.onProviderRegistered(...this.onProviderRegisteredHookList);
|
|
77
82
|
for (const registration of this.getRegistrations()) {
|
|
78
83
|
registration.applyTo(scope);
|
|
79
84
|
}
|
|
@@ -110,6 +115,7 @@ export class Container {
|
|
|
110
115
|
this.onConstructHookList.length = 0;
|
|
111
116
|
this.onDisposeHookList.length = 0;
|
|
112
117
|
this.onScopeCreatedHookList.length = 0;
|
|
118
|
+
this.onProviderRegisteredHookList.length = 0;
|
|
113
119
|
}
|
|
114
120
|
addRegistration(registration) {
|
|
115
121
|
this.registrations.push(registration);
|
|
@@ -134,6 +140,10 @@ export class Container {
|
|
|
134
140
|
this.onScopeCreatedHookList.push(...hooks);
|
|
135
141
|
return this;
|
|
136
142
|
}
|
|
143
|
+
onProviderRegistered(...hooks) {
|
|
144
|
+
this.onProviderRegisteredHookList.push(...hooks);
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
137
147
|
addInstance(instance) {
|
|
138
148
|
this.instances.add(instance);
|
|
139
149
|
for (const onConstruct of this.onConstructHookList) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-ioc-container",
|
|
3
|
-
"version": "60.
|
|
3
|
+
"version": "60.2.0",
|
|
4
4
|
"description": "Fast, lightweight TypeScript dependency injection container with a clean API, scoped lifecycles, decorators, tokens, hooks, lazy injection, customizable providers, and no global container objects.",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AutoResolveOptions, type CreateScopeOptions, type DependencyKey, type IContainer, type IContainerModule, type InstanceHook, type RegisterOptions, ResolveManyOptions, type ResolveOneOptions, type ScopeHook, type Tag } from './IContainer.js';
|
|
1
|
+
import { type AutoResolveOptions, type CreateScopeOptions, type DependencyKey, type IContainer, type IContainerModule, type InstanceHook, type ProviderHook, type RegisterOptions, ResolveManyOptions, type ResolveOneOptions, type ScopeHook, type Tag } from './IContainer.js';
|
|
2
2
|
import { type IInjector } from '../injector/IInjector.js';
|
|
3
3
|
import { type IProvider } from '../provider/IProvider.js';
|
|
4
4
|
import { type IRegistration } from '../registration/IRegistration.js';
|
|
@@ -17,6 +17,7 @@ export declare class Container implements IContainer {
|
|
|
17
17
|
private readonly onConstructHookList;
|
|
18
18
|
private readonly onDisposeHookList;
|
|
19
19
|
private readonly onScopeCreatedHookList;
|
|
20
|
+
private readonly onProviderRegisteredHookList;
|
|
20
21
|
constructor(options?: {
|
|
21
22
|
injector?: IInjector;
|
|
22
23
|
parent?: IContainer;
|
|
@@ -35,6 +36,7 @@ export declare class Container implements IContainer {
|
|
|
35
36
|
onConstruct(...hooks: InstanceHook[]): this;
|
|
36
37
|
onInstanceDisposed(...hooks: OnDisposeHook[]): this;
|
|
37
38
|
onScopeCreated(...hooks: ScopeHook[]): this;
|
|
39
|
+
onProviderRegistered(...hooks: ProviderHook[]): this;
|
|
38
40
|
addInstance(instance: Instance): void;
|
|
39
41
|
getScopes(): IContainer[];
|
|
40
42
|
hasInstance(instance: Instance): boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AutoResolveOptions, type DependencyKey, type IContainer, type IContainerModule, type ScopeHook, type ResolveManyOptions, type ResolveOneOptions, type Tag, type InstanceHook } from './IContainer.js';
|
|
1
|
+
import { type AutoResolveOptions, type DependencyKey, type IContainer, type IContainerModule, type ScopeHook, type ProviderHook, type ResolveManyOptions, type ResolveOneOptions, type Tag, type InstanceHook } from './IContainer.js';
|
|
2
2
|
import { type IProvider } from '../provider/IProvider.js';
|
|
3
3
|
import { type IRegistration } from '../registration/IRegistration.js';
|
|
4
4
|
import { OnDisposeHook } from '../hooks/onContainerDisposed.js';
|
|
@@ -27,4 +27,5 @@ export declare class EmptyContainer implements IContainer {
|
|
|
27
27
|
onInstanceDisposed(...hooks: OnDisposeHook[]): this;
|
|
28
28
|
onConstruct(...hooks: InstanceHook[]): this;
|
|
29
29
|
onScopeCreated(...hooks: ScopeHook[]): this;
|
|
30
|
+
onProviderRegistered(...hooks: ProviderHook[]): this;
|
|
30
31
|
}
|
|
@@ -35,11 +35,13 @@ export type RegisterOptions = {
|
|
|
35
35
|
export type ScopeHook = (scope: IContainer) => void;
|
|
36
36
|
export type InstanceHook = (instance: Instance, scope: IContainer) => void;
|
|
37
37
|
export type DependencyHook = (dependency: unknown, scope: IContainer) => void;
|
|
38
|
+
export type ProviderHook = (provider: IProvider, key: DependencyKey, scope: IContainer) => void;
|
|
38
39
|
export interface IContainer extends Tagged {
|
|
39
40
|
readonly isDisposed: boolean;
|
|
40
41
|
onConstruct(...hooks: InstanceHook[]): this;
|
|
41
42
|
onInstanceDisposed(...hooks: OnDisposeHook[]): this;
|
|
42
43
|
onScopeCreated(...hooks: ScopeHook[]): this;
|
|
44
|
+
onProviderRegistered(...hooks: ProviderHook[]): this;
|
|
43
45
|
register(key: DependencyKey, value: IProvider, options?: RegisterOptions): this;
|
|
44
46
|
addRegistration(registration: IRegistration): this;
|
|
45
47
|
getRegistrations(): IRegistration[];
|
package/typings/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { type IContainer, type Resolvable, type IContainerModule, type DependencyKey, type Tag, type Tagged, type ResolveOneOptions, type ResolveManyOptions, type ScopeHook, type InstanceHook, type DependencyHook, type AutoResolveOptions, isDependencyKey, } from './container/IContainer.js';
|
|
1
|
+
export { type IContainer, type Resolvable, type IContainerModule, type DependencyKey, type Tag, type Tagged, type ResolveOneOptions, type ResolveManyOptions, type ScopeHook, type InstanceHook, type DependencyHook, type ProviderHook, type AutoResolveOptions, isDependencyKey, } from './container/IContainer.js';
|
|
2
2
|
export { Container } from './container/Container.js';
|
|
3
3
|
export { AutoResolveModule } from './container/AutoResolveModule.js';
|
|
4
4
|
export { EmptyContainer } from './container/EmptyContainer.js';
|