@lad-tech/nsc-toolkit 1.15.0 → 1.15.2
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/CHANGELOG.md +3 -3
- package/dist/Container.js +2 -1
- package/dist/Service.js +2 -2
- package/dist/types/Container.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
## [1.15.2](https://github.com/lad-tech/nsc-toolkit/compare/v1.15.1...v1.15.2) (2023-08-16)
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
###
|
|
4
|
+
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
*
|
|
6
|
+
* singlton inject ([#75](https://github.com/lad-tech/nsc-toolkit/issues/75)) ([b57e386](https://github.com/lad-tech/nsc-toolkit/commit/b57e386532d32a3ea2bbf9940d8c2b4ae6fa85ab))
|
package/dist/Container.js
CHANGED
|
@@ -107,13 +107,14 @@ class Container {
|
|
|
107
107
|
throw new Error(`Unknown dependency type for key ${key.toString()}`);
|
|
108
108
|
}
|
|
109
109
|
async initDependencies() {
|
|
110
|
-
var _a;
|
|
110
|
+
var _a, _b;
|
|
111
111
|
const initialized = [];
|
|
112
112
|
for await (const [key, dependency] of this.container) {
|
|
113
113
|
if (this.isAdapterDependency(dependency) && ((_a = dependency.options) === null || _a === void 0 ? void 0 : _a.init) && !this.singltons.has(key)) {
|
|
114
114
|
const instance = this.getInstance(key);
|
|
115
115
|
await (instance === null || instance === void 0 ? void 0 : instance.init());
|
|
116
116
|
initialized.push(instance);
|
|
117
|
+
this.singltons.set(key, { value: instance, init: (_b = dependency.options) === null || _b === void 0 ? void 0 : _b.init });
|
|
117
118
|
}
|
|
118
119
|
}
|
|
119
120
|
return initialized;
|
package/dist/Service.js
CHANGED
|
@@ -128,12 +128,12 @@ class Service extends Root_1.Root {
|
|
|
128
128
|
if (Array.isArray(dependencyKey)) {
|
|
129
129
|
if (propertyName === _1.ConstructorDependencyKey) {
|
|
130
130
|
dependencyKey.forEach((item, index) => {
|
|
131
|
-
const { dependency
|
|
131
|
+
const { dependency } = _1.container.get(item);
|
|
132
132
|
if (dependency.type === _1.DependencyType.SERVICE) {
|
|
133
133
|
dependences[_1.ConstructorDependencyKey][index] = new dependency.value(this.broker, baggage, this.options.cache);
|
|
134
134
|
}
|
|
135
135
|
if (dependency.type === _1.DependencyType.ADAPTER) {
|
|
136
|
-
const instance =
|
|
136
|
+
const instance = _1.container.getInstance(item);
|
|
137
137
|
const trap = this.getTrap(instance, tracer, baggage);
|
|
138
138
|
dependences[_1.ConstructorDependencyKey][index] = new Proxy(instance, trap);
|
|
139
139
|
}
|
|
@@ -29,7 +29,7 @@ declare class Container {
|
|
|
29
29
|
bind<R extends Record<string, any>>(key: symbol, type: typeof DependencyType.CONSTANT, value: R): void;
|
|
30
30
|
symbol(key: symbol): {
|
|
31
31
|
to: {
|
|
32
|
-
Adapter: <R extends Record<string, any>>(value: Adapter<R & import("./interfaces").GracefulShutdownAdditionalService & {
|
|
32
|
+
Adapter: <R extends Record<string, any>>(value: Adapter<R> | Adapter<R & import("./interfaces").GracefulShutdownAdditionalService & {
|
|
33
33
|
init: () => Promise<any>;
|
|
34
34
|
}>, options?: AdapterOptions) => void;
|
|
35
35
|
Singlton: <R_1 extends Record<string, any>>(value: Adapter<R_1>) => void;
|