@zenofolio/hyper-decor 1.0.52 → 1.0.53
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.
|
@@ -75,16 +75,7 @@ function prepareApplication(options, Target, app, log) {
|
|
|
75
75
|
const data = getData(Target);
|
|
76
76
|
const prefix = (_a = options.prefix) !== null && _a !== void 0 ? _a : "/";
|
|
77
77
|
const imports = (_b = options.imports) !== null && _b !== void 0 ? _b : [];
|
|
78
|
-
|
|
79
|
-
// initialize servies stored
|
|
80
|
-
for (const service of service_store_1.serviceStore) {
|
|
81
|
-
const instance = tsyringe_1.container.resolve(service);
|
|
82
|
-
if (instance.onInit)
|
|
83
|
-
yield instance.onInit();
|
|
84
|
-
}
|
|
85
|
-
// clean up the service store
|
|
86
|
-
service_store_1.serviceStore.clear();
|
|
87
|
-
}
|
|
78
|
+
yield prepareServices(service_store_1.serviceStore);
|
|
88
79
|
yield (0, imports_helper_1.prepareImports)(Target, imports);
|
|
89
80
|
if (data.middlewares.length) {
|
|
90
81
|
app.use(...data.middlewares);
|
|
@@ -246,3 +237,12 @@ function prepareRoutes(_a) {
|
|
|
246
237
|
}
|
|
247
238
|
});
|
|
248
239
|
}
|
|
240
|
+
function prepareServices(list) {
|
|
241
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
242
|
+
yield Promise.all(Array.from(list).map((service) => __awaiter(this, void 0, void 0, function* () {
|
|
243
|
+
const instance = tsyringe_1.container.resolve(service);
|
|
244
|
+
if (instance.onInit)
|
|
245
|
+
yield instance.onInit();
|
|
246
|
+
})));
|
|
247
|
+
});
|
|
248
|
+
}
|
|
@@ -3,18 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Service = void 0;
|
|
4
4
|
const tsyringe_1 = require("tsyringe");
|
|
5
5
|
const service_store_1 = require("../__internals/stores/service.store");
|
|
6
|
-
const Service = () => {
|
|
6
|
+
const Service = ({ singleton = true, } = {}) => {
|
|
7
7
|
return (target) => {
|
|
8
|
-
if (!service_store_1.serviceStore.has(target)) {
|
|
9
|
-
service_store_1.serviceStore.add(target);
|
|
10
|
-
}
|
|
11
|
-
const instance = tsyringe_1.container.resolve(target);
|
|
12
8
|
if (!tsyringe_1.container.isRegistered(target)) {
|
|
13
|
-
|
|
9
|
+
singleton
|
|
10
|
+
? tsyringe_1.container.registerSingleton(target)
|
|
11
|
+
: tsyringe_1.container.register(target, target);
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
return instance;
|
|
17
|
-
};
|
|
13
|
+
service_store_1.serviceStore.add(target);
|
|
18
14
|
};
|
|
19
15
|
};
|
|
20
16
|
exports.Service = Service;
|