ts-ioc-container 43.0.1 → 43.1.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/README.md +10 -2
- package/cjm/container/AliasMap.js +8 -8
- package/cjm/container/AutoMockedContainer.js +1 -0
- package/cjm/container/Container.js +32 -18
- package/cjm/container/EmptyContainer.js +1 -0
- package/cjm/index.js +4 -2
- package/cjm/injector/IInjector.js +3 -1
- package/esm/container/AliasMap.js +8 -8
- package/esm/container/AutoMockedContainer.js +1 -0
- package/esm/container/Container.js +32 -18
- package/esm/container/EmptyContainer.js +1 -0
- package/esm/index.js +1 -0
- package/esm/injector/IInjector.js +3 -1
- package/package.json +1 -1
- package/typings/container/AliasMap.d.ts +2 -2
- package/typings/container/AutoMockedContainer.d.ts +1 -0
- package/typings/container/Container.d.ts +7 -4
- package/typings/container/EmptyContainer.d.ts +2 -1
- package/typings/container/IContainer.d.ts +2 -1
- package/typings/hooks/onConstruct.d.ts +2 -0
- package/typings/hooks/onDispose.d.ts +2 -0
- package/typings/index.d.ts +1 -0
package/README.md
CHANGED
|
@@ -1261,8 +1261,16 @@ Sometimes you want to register provider with certain key. This is what `key` is
|
|
|
1261
1261
|
- you can assign the same key to different registrations
|
|
1262
1262
|
|
|
1263
1263
|
```typescript
|
|
1264
|
-
import {
|
|
1265
|
-
|
|
1264
|
+
import {
|
|
1265
|
+
bindTo,
|
|
1266
|
+
Container,
|
|
1267
|
+
DependencyMissingKeyError,
|
|
1268
|
+
register,
|
|
1269
|
+
Registration as R,
|
|
1270
|
+
scope,
|
|
1271
|
+
singleton,
|
|
1272
|
+
toAlias,
|
|
1273
|
+
} from 'ts-ioc-container';
|
|
1266
1274
|
|
|
1267
1275
|
describe('Registration module', function () {
|
|
1268
1276
|
const createContainer = () => new Container({ tags: ['root'] });
|
|
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.AliasMap = void 0;
|
|
4
4
|
class AliasMap {
|
|
5
5
|
aliasToKeySet = new Map();
|
|
6
|
-
|
|
7
|
-
for (const [
|
|
8
|
-
|
|
9
|
-
if (
|
|
10
|
-
this.aliasToKeySet.delete(
|
|
6
|
+
deleteAliasesByKey(key) {
|
|
7
|
+
for (const [alias, keySet] of this.aliasToKeySet) {
|
|
8
|
+
keySet.delete(key);
|
|
9
|
+
if (keySet.size === 0) {
|
|
10
|
+
this.aliasToKeySet.delete(alias);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
findManyKeysByAlias(alias) {
|
|
15
15
|
return [...(this.aliasToKeySet.get(alias) ?? [])];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
setAliases(key, aliases) {
|
|
18
18
|
for (const alias of aliases) {
|
|
19
|
-
const
|
|
20
|
-
this.aliasToKeySet.set(alias,
|
|
19
|
+
const dependencyKeySet = this.aliasToKeySet.get(alias) ?? new Set();
|
|
20
|
+
this.aliasToKeySet.set(alias, dependencyKeySet.add(key));
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
destroy() {
|
|
@@ -4,6 +4,7 @@ exports.AutoMockedContainer = void 0;
|
|
|
4
4
|
const MethodNotImplementedError_1 = require("../errors/MethodNotImplementedError");
|
|
5
5
|
class AutoMockedContainer {
|
|
6
6
|
isDisposed = false;
|
|
7
|
+
onInstanceCreated(instance) { }
|
|
7
8
|
createScope() {
|
|
8
9
|
throw new MethodNotImplementedError_1.MethodNotImplementedError();
|
|
9
10
|
}
|
|
@@ -16,21 +16,34 @@ class Container {
|
|
|
16
16
|
providers = new Map();
|
|
17
17
|
aliases = new AliasMap_1.AliasMap();
|
|
18
18
|
registrations = new Set();
|
|
19
|
-
onConstruct;
|
|
20
|
-
onDispose;
|
|
21
19
|
injector;
|
|
20
|
+
onConstructHookList = [];
|
|
21
|
+
onDisposeHookList = [];
|
|
22
22
|
constructor(options = {}) {
|
|
23
23
|
this.injector = options.injector ?? new MetadataInjector_1.MetadataInjector();
|
|
24
24
|
this.parent = options.parent ?? new EmptyContainer_1.EmptyContainer();
|
|
25
25
|
this.tags = new Set(options.tags ?? []);
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
}
|
|
27
|
+
addOnConstructHook(...hooks) {
|
|
28
|
+
this.onConstructHookList.push(...hooks);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
addOnDisposeHook(...hooks) {
|
|
32
|
+
this.onDisposeHookList.push(...hooks);
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
onInstanceCreated(instance) {
|
|
36
|
+
this.instances.add(instance);
|
|
37
|
+
// Execute onConstruct hooks
|
|
38
|
+
for (const onConstruct of this.onConstructHookList) {
|
|
39
|
+
onConstruct(instance, this);
|
|
40
|
+
}
|
|
28
41
|
}
|
|
29
42
|
register(key, provider, { aliases = [] } = {}) {
|
|
30
43
|
this.validateContainer();
|
|
31
44
|
this.providers.set(key, provider);
|
|
32
|
-
this.aliases.
|
|
33
|
-
this.aliases.
|
|
45
|
+
this.aliases.deleteAliasesByKey(key);
|
|
46
|
+
this.aliases.setAliases(key, aliases);
|
|
34
47
|
return this;
|
|
35
48
|
}
|
|
36
49
|
addRegistration(registration) {
|
|
@@ -44,19 +57,14 @@ class Container {
|
|
|
44
57
|
resolve(keyOrAlias, { args = [], child = this, lazy } = {}) {
|
|
45
58
|
this.validateContainer();
|
|
46
59
|
if (utils_1.Is.constructor(keyOrAlias)) {
|
|
47
|
-
return (0, utils_1.toLazyIf)(() => {
|
|
48
|
-
const instance = this.injector.resolve(this, keyOrAlias, { args });
|
|
49
|
-
this.instances.add(instance);
|
|
50
|
-
this.onConstruct(instance, this);
|
|
51
|
-
return instance;
|
|
52
|
-
}, lazy);
|
|
60
|
+
return (0, utils_1.toLazyIf)(() => this.injector.resolve(this, keyOrAlias, { args }), lazy);
|
|
53
61
|
}
|
|
54
62
|
const provider = this.providers.get(keyOrAlias);
|
|
55
63
|
return provider?.hasAccess({ invocationScope: child, providerScope: this })
|
|
56
64
|
? provider.resolve(this, { args, lazy })
|
|
57
65
|
: this.parent.resolve(keyOrAlias, { args, child, lazy });
|
|
58
66
|
}
|
|
59
|
-
resolveByAlias(alias, { args = [], child = this, lazy, excludedKeys =
|
|
67
|
+
resolveByAlias(alias, { args = [], child = this, lazy, excludedKeys = [], takeFirst = -1 } = {}) {
|
|
60
68
|
this.validateContainer();
|
|
61
69
|
let left = takeFirst;
|
|
62
70
|
const keys = [];
|
|
@@ -78,7 +86,7 @@ class Container {
|
|
|
78
86
|
args,
|
|
79
87
|
child,
|
|
80
88
|
lazy,
|
|
81
|
-
excludedKeys:
|
|
89
|
+
excludedKeys: [...excludedKeys, ...keys],
|
|
82
90
|
});
|
|
83
91
|
return [...deps, ...parentDeps];
|
|
84
92
|
}
|
|
@@ -88,9 +96,9 @@ class Container {
|
|
|
88
96
|
injector: this.injector,
|
|
89
97
|
parent: this,
|
|
90
98
|
tags,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
})
|
|
100
|
+
.addOnConstructHook(...this.onConstructHookList)
|
|
101
|
+
.addOnDisposeHook(...this.onDisposeHookList);
|
|
94
102
|
scope.applyRegistrationsFrom(this);
|
|
95
103
|
this.scopes.add(scope);
|
|
96
104
|
return scope;
|
|
@@ -125,7 +133,13 @@ class Container {
|
|
|
125
133
|
this.aliases.destroy();
|
|
126
134
|
this.instances.clear();
|
|
127
135
|
this.registrations.clear();
|
|
128
|
-
|
|
136
|
+
// Clear hooks
|
|
137
|
+
this.onConstructHookList.splice(0, this.onConstructHookList.length);
|
|
138
|
+
// Execute onDispose hooks
|
|
139
|
+
while (this.onDisposeHookList.length) {
|
|
140
|
+
const onDispose = this.onDisposeHookList.shift();
|
|
141
|
+
onDispose(this);
|
|
142
|
+
}
|
|
129
143
|
}
|
|
130
144
|
/**
|
|
131
145
|
* @private
|
package/cjm/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.SyncHooksRunner = exports.AsyncHooksRunner = exports.toToken = exports.Is = exports.select = exports.InstanceListToken = void 0;
|
|
3
|
+
exports.FunctionToken = exports.StringToken = exports.ClassToken = exports.toAlias = exports.AliasToken = exports.InjectionToken = exports.getParameterMetadata = exports.getMethodMetadata = exports.setMethodMetadata = exports.setParameterMetadata = exports.getMetadata = exports.setMetadata = exports.onDispose = exports.onDisposeHooksRunner = exports.onConstruct = exports.onConstructHooksRunner = exports.injectProp = exports.HookContext = exports.hasHooks = exports.hook = exports.getHooks = exports.UnexpectedHookResultError = exports.ContainerDisposedError = exports.MethodNotImplementedError = exports.DependencyMissingKeyError = exports.DependencyNotFoundError = exports.Registration = exports.bindTo = exports.register = exports.scope = exports.decorate = exports.MultiCache = exports.multiCache = exports.SingletonProvider = exports.singleton = exports.Provider = exports.resolveByArgs = exports.ProviderDecorator = exports.args = exports.argsFn = exports.lazy = exports.scopeAccess = exports.ProxyInjector = exports.SimpleInjector = exports.MetadataInjector = exports.resolveArgs = exports.inject = exports.AutoMockedContainer = exports.EmptyContainer = exports.Container = void 0;
|
|
4
|
+
exports.SyncHooksRunner = exports.AsyncHooksRunner = exports.toToken = exports.Is = exports.select = exports.InstanceListToken = exports.ConstantToken = void 0;
|
|
5
5
|
var Container_1 = require("./container/Container");
|
|
6
6
|
Object.defineProperty(exports, "Container", { enumerable: true, get: function () { return Container_1.Container; } });
|
|
7
7
|
var EmptyContainer_1 = require("./container/EmptyContainer");
|
|
@@ -46,6 +46,8 @@ Object.defineProperty(exports, "Registration", { enumerable: true, get: function
|
|
|
46
46
|
// Errors
|
|
47
47
|
var DependencyNotFoundError_1 = require("./errors/DependencyNotFoundError");
|
|
48
48
|
Object.defineProperty(exports, "DependencyNotFoundError", { enumerable: true, get: function () { return DependencyNotFoundError_1.DependencyNotFoundError; } });
|
|
49
|
+
var DependencyMissingKeyError_1 = require("./errors/DependencyMissingKeyError");
|
|
50
|
+
Object.defineProperty(exports, "DependencyMissingKeyError", { enumerable: true, get: function () { return DependencyMissingKeyError_1.DependencyMissingKeyError; } });
|
|
49
51
|
var MethodNotImplementedError_1 = require("./errors/MethodNotImplementedError");
|
|
50
52
|
Object.defineProperty(exports, "MethodNotImplementedError", { enumerable: true, get: function () { return MethodNotImplementedError_1.MethodNotImplementedError; } });
|
|
51
53
|
var ContainerDisposedError_1 = require("./errors/ContainerDisposedError");
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Injector = void 0;
|
|
4
4
|
class Injector {
|
|
5
5
|
resolve(scope, Target, options) {
|
|
6
|
-
|
|
6
|
+
const instance = this.createInstance(scope, Target, options);
|
|
7
|
+
scope.onInstanceCreated(instance);
|
|
8
|
+
return instance;
|
|
7
9
|
}
|
|
8
10
|
}
|
|
9
11
|
exports.Injector = Injector;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
export class AliasMap {
|
|
2
2
|
aliasToKeySet = new Map();
|
|
3
|
-
|
|
4
|
-
for (const [
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
this.aliasToKeySet.delete(
|
|
3
|
+
deleteAliasesByKey(key) {
|
|
4
|
+
for (const [alias, keySet] of this.aliasToKeySet) {
|
|
5
|
+
keySet.delete(key);
|
|
6
|
+
if (keySet.size === 0) {
|
|
7
|
+
this.aliasToKeySet.delete(alias);
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
findManyKeysByAlias(alias) {
|
|
12
12
|
return [...(this.aliasToKeySet.get(alias) ?? [])];
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
setAliases(key, aliases) {
|
|
15
15
|
for (const alias of aliases) {
|
|
16
|
-
const
|
|
17
|
-
this.aliasToKeySet.set(alias,
|
|
16
|
+
const dependencyKeySet = this.aliasToKeySet.get(alias) ?? new Set();
|
|
17
|
+
this.aliasToKeySet.set(alias, dependencyKeySet.add(key));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
destroy() {
|
|
@@ -13,21 +13,34 @@ export class Container {
|
|
|
13
13
|
providers = new Map();
|
|
14
14
|
aliases = new AliasMap();
|
|
15
15
|
registrations = new Set();
|
|
16
|
-
onConstruct;
|
|
17
|
-
onDispose;
|
|
18
16
|
injector;
|
|
17
|
+
onConstructHookList = [];
|
|
18
|
+
onDisposeHookList = [];
|
|
19
19
|
constructor(options = {}) {
|
|
20
20
|
this.injector = options.injector ?? new MetadataInjector();
|
|
21
21
|
this.parent = options.parent ?? new EmptyContainer();
|
|
22
22
|
this.tags = new Set(options.tags ?? []);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
}
|
|
24
|
+
addOnConstructHook(...hooks) {
|
|
25
|
+
this.onConstructHookList.push(...hooks);
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
addOnDisposeHook(...hooks) {
|
|
29
|
+
this.onDisposeHookList.push(...hooks);
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
onInstanceCreated(instance) {
|
|
33
|
+
this.instances.add(instance);
|
|
34
|
+
// Execute onConstruct hooks
|
|
35
|
+
for (const onConstruct of this.onConstructHookList) {
|
|
36
|
+
onConstruct(instance, this);
|
|
37
|
+
}
|
|
25
38
|
}
|
|
26
39
|
register(key, provider, { aliases = [] } = {}) {
|
|
27
40
|
this.validateContainer();
|
|
28
41
|
this.providers.set(key, provider);
|
|
29
|
-
this.aliases.
|
|
30
|
-
this.aliases.
|
|
42
|
+
this.aliases.deleteAliasesByKey(key);
|
|
43
|
+
this.aliases.setAliases(key, aliases);
|
|
31
44
|
return this;
|
|
32
45
|
}
|
|
33
46
|
addRegistration(registration) {
|
|
@@ -41,19 +54,14 @@ export class Container {
|
|
|
41
54
|
resolve(keyOrAlias, { args = [], child = this, lazy } = {}) {
|
|
42
55
|
this.validateContainer();
|
|
43
56
|
if (Is.constructor(keyOrAlias)) {
|
|
44
|
-
return toLazyIf(() => {
|
|
45
|
-
const instance = this.injector.resolve(this, keyOrAlias, { args });
|
|
46
|
-
this.instances.add(instance);
|
|
47
|
-
this.onConstruct(instance, this);
|
|
48
|
-
return instance;
|
|
49
|
-
}, lazy);
|
|
57
|
+
return toLazyIf(() => this.injector.resolve(this, keyOrAlias, { args }), lazy);
|
|
50
58
|
}
|
|
51
59
|
const provider = this.providers.get(keyOrAlias);
|
|
52
60
|
return provider?.hasAccess({ invocationScope: child, providerScope: this })
|
|
53
61
|
? provider.resolve(this, { args, lazy })
|
|
54
62
|
: this.parent.resolve(keyOrAlias, { args, child, lazy });
|
|
55
63
|
}
|
|
56
|
-
resolveByAlias(alias, { args = [], child = this, lazy, excludedKeys =
|
|
64
|
+
resolveByAlias(alias, { args = [], child = this, lazy, excludedKeys = [], takeFirst = -1 } = {}) {
|
|
57
65
|
this.validateContainer();
|
|
58
66
|
let left = takeFirst;
|
|
59
67
|
const keys = [];
|
|
@@ -75,7 +83,7 @@ export class Container {
|
|
|
75
83
|
args,
|
|
76
84
|
child,
|
|
77
85
|
lazy,
|
|
78
|
-
excludedKeys:
|
|
86
|
+
excludedKeys: [...excludedKeys, ...keys],
|
|
79
87
|
});
|
|
80
88
|
return [...deps, ...parentDeps];
|
|
81
89
|
}
|
|
@@ -85,9 +93,9 @@ export class Container {
|
|
|
85
93
|
injector: this.injector,
|
|
86
94
|
parent: this,
|
|
87
95
|
tags,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
96
|
+
})
|
|
97
|
+
.addOnConstructHook(...this.onConstructHookList)
|
|
98
|
+
.addOnDisposeHook(...this.onDisposeHookList);
|
|
91
99
|
scope.applyRegistrationsFrom(this);
|
|
92
100
|
this.scopes.add(scope);
|
|
93
101
|
return scope;
|
|
@@ -122,7 +130,13 @@ export class Container {
|
|
|
122
130
|
this.aliases.destroy();
|
|
123
131
|
this.instances.clear();
|
|
124
132
|
this.registrations.clear();
|
|
125
|
-
|
|
133
|
+
// Clear hooks
|
|
134
|
+
this.onConstructHookList.splice(0, this.onConstructHookList.length);
|
|
135
|
+
// Execute onDispose hooks
|
|
136
|
+
while (this.onDisposeHookList.length) {
|
|
137
|
+
const onDispose = this.onDisposeHookList.shift();
|
|
138
|
+
onDispose(this);
|
|
139
|
+
}
|
|
126
140
|
}
|
|
127
141
|
/**
|
|
128
142
|
* @private
|
package/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export { scope, register, bindTo, } from './registration/IRegistration';
|
|
|
17
17
|
export { Registration } from './registration/Registration';
|
|
18
18
|
// Errors
|
|
19
19
|
export { DependencyNotFoundError } from './errors/DependencyNotFoundError';
|
|
20
|
+
export { DependencyMissingKeyError } from './errors/DependencyMissingKeyError';
|
|
20
21
|
export { MethodNotImplementedError } from './errors/MethodNotImplementedError';
|
|
21
22
|
export { ContainerDisposedError } from './errors/ContainerDisposedError';
|
|
22
23
|
export { UnexpectedHookResultError } from './errors/UnexpectedHookResultError';
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@ import { type DependencyKey } from './IContainer';
|
|
|
2
2
|
export type Alias = DependencyKey;
|
|
3
3
|
export declare class AliasMap {
|
|
4
4
|
private readonly aliasToKeySet;
|
|
5
|
-
|
|
5
|
+
deleteAliasesByKey(key: DependencyKey): void;
|
|
6
6
|
findManyKeysByAlias(alias: DependencyKey): DependencyKey[];
|
|
7
|
-
|
|
7
|
+
setAliases(key: DependencyKey, aliases: DependencyKey[]): void;
|
|
8
8
|
destroy(): void;
|
|
9
9
|
}
|
|
@@ -3,6 +3,7 @@ import { type IRegistration } from '../registration/IRegistration';
|
|
|
3
3
|
import { type constructor } from '../utils';
|
|
4
4
|
export declare abstract class AutoMockedContainer implements IContainer {
|
|
5
5
|
isDisposed: boolean;
|
|
6
|
+
onInstanceCreated(instance: Instance): void;
|
|
6
7
|
createScope(): IContainer;
|
|
7
8
|
dispose(): void;
|
|
8
9
|
register(): this;
|
|
@@ -3,6 +3,8 @@ import { type IInjector } from '../injector/IInjector';
|
|
|
3
3
|
import { type IProvider } from '../provider/IProvider';
|
|
4
4
|
import { type IRegistration } from '../registration/IRegistration';
|
|
5
5
|
import { type constructor } from '../utils';
|
|
6
|
+
import { OnConstructHook } from '../hooks/onConstruct';
|
|
7
|
+
import { OnDisposeHook } from '../hooks/onDispose';
|
|
6
8
|
export declare class Container implements IContainer {
|
|
7
9
|
isDisposed: boolean;
|
|
8
10
|
private parent;
|
|
@@ -12,16 +14,17 @@ export declare class Container implements IContainer {
|
|
|
12
14
|
private readonly providers;
|
|
13
15
|
private readonly aliases;
|
|
14
16
|
private readonly registrations;
|
|
15
|
-
private readonly onConstruct;
|
|
16
|
-
private readonly onDispose;
|
|
17
17
|
private readonly injector;
|
|
18
|
+
private readonly onConstructHookList;
|
|
19
|
+
private readonly onDisposeHookList;
|
|
18
20
|
constructor(options?: {
|
|
19
21
|
injector?: IInjector;
|
|
20
22
|
parent?: IContainer;
|
|
21
23
|
tags?: Tag[];
|
|
22
|
-
onConstruct?: (instance: Instance, scope: IContainer) => void;
|
|
23
|
-
onDispose?: (scope: IContainer) => void;
|
|
24
24
|
});
|
|
25
|
+
addOnConstructHook(...hooks: OnConstructHook[]): this;
|
|
26
|
+
addOnDisposeHook(...hooks: OnDisposeHook[]): this;
|
|
27
|
+
onInstanceCreated(instance: Instance): void;
|
|
25
28
|
register(key: DependencyKey, provider: IProvider, { aliases }?: RegisterOptions): this;
|
|
26
29
|
addRegistration(registration: IRegistration): this;
|
|
27
30
|
getRegistrations(): IRegistration[];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { type DependencyKey, type IContainer, type IContainerModule, type ResolveManyOptions, type ResolveOneOptions, type Tag } from './IContainer';
|
|
1
|
+
import { type DependencyKey, type IContainer, type IContainerModule, Instance, type ResolveManyOptions, type ResolveOneOptions, type Tag } from './IContainer';
|
|
2
2
|
import { type IProvider } from '../provider/IProvider';
|
|
3
3
|
import { type IRegistration } from '../registration/IRegistration';
|
|
4
4
|
import { type constructor } from '../utils';
|
|
5
5
|
export declare class EmptyContainer implements IContainer {
|
|
6
6
|
get isDisposed(): boolean;
|
|
7
|
+
onInstanceCreated(instance: Instance): void;
|
|
7
8
|
getParent(): undefined;
|
|
8
9
|
getScopes(): never[];
|
|
9
10
|
getInstances(): never[];
|
|
@@ -8,7 +8,7 @@ type WithChild = {
|
|
|
8
8
|
};
|
|
9
9
|
export type ResolveOneOptions = ProviderOptions & Partial<WithChild>;
|
|
10
10
|
type WithExcludedKeys = {
|
|
11
|
-
excludedKeys:
|
|
11
|
+
excludedKeys: DependencyKey[];
|
|
12
12
|
};
|
|
13
13
|
type TakeFirst = {
|
|
14
14
|
takeFirst: number;
|
|
@@ -47,5 +47,6 @@ export interface IContainer extends Tagged {
|
|
|
47
47
|
getParent(): IContainer | undefined;
|
|
48
48
|
getInstances(): Instance[];
|
|
49
49
|
dispose(): void;
|
|
50
|
+
onInstanceCreated(instance: Instance): void;
|
|
50
51
|
}
|
|
51
52
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { HookFn } from './hook';
|
|
2
2
|
import { SyncHooksRunner } from './runner/SyncHooksRunner';
|
|
3
|
+
import type { IContainer, Instance } from '../container/IContainer';
|
|
3
4
|
export declare const onConstructHooksRunner: SyncHooksRunner;
|
|
4
5
|
export declare const onConstruct: (fn: HookFn) => (target: object, propertyKey: string | symbol) => void;
|
|
6
|
+
export type OnConstructHook = (instance: Instance, scope: IContainer) => void;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { SyncHooksRunner } from './runner/SyncHooksRunner';
|
|
2
|
+
import type { IContainer } from '../container/IContainer';
|
|
2
3
|
export declare const onDisposeHooksRunner: SyncHooksRunner;
|
|
3
4
|
export declare const onDispose: (target: object, propertyKey: string | symbol) => void;
|
|
5
|
+
export type OnDisposeHook = (scope: IContainer) => void;
|
package/typings/index.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export { type ProviderPipe } from './provider/ProviderPipe';
|
|
|
16
16
|
export { type IRegistration, type ReturnTypeOfRegistration, scope, register, type ScopePredicate, bindTo, } from './registration/IRegistration';
|
|
17
17
|
export { Registration } from './registration/Registration';
|
|
18
18
|
export { DependencyNotFoundError } from './errors/DependencyNotFoundError';
|
|
19
|
+
export { DependencyMissingKeyError } from './errors/DependencyMissingKeyError';
|
|
19
20
|
export { MethodNotImplementedError } from './errors/MethodNotImplementedError';
|
|
20
21
|
export { ContainerDisposedError } from './errors/ContainerDisposedError';
|
|
21
22
|
export { UnexpectedHookResultError } from './errors/UnexpectedHookResultError';
|