@zenofolio/hyper-decor 1.0.51 → 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,6 +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
|
+
yield prepareServices(service_store_1.serviceStore);
|
|
78
79
|
yield (0, imports_helper_1.prepareImports)(Target, imports);
|
|
79
80
|
if (data.middlewares.length) {
|
|
80
81
|
app.use(...data.middlewares);
|
|
@@ -109,16 +110,6 @@ function prepareApplication(options, Target, app, log) {
|
|
|
109
110
|
routers.forEach(({ router, path }) => {
|
|
110
111
|
app.use((0, path_util_1.join)(prefix, path), router);
|
|
111
112
|
});
|
|
112
|
-
{
|
|
113
|
-
// initialize servies stored
|
|
114
|
-
for (const service of service_store_1.serviceStore) {
|
|
115
|
-
const instance = tsyringe_1.container.resolve(service);
|
|
116
|
-
if (instance.onInit)
|
|
117
|
-
yield instance.onInit();
|
|
118
|
-
}
|
|
119
|
-
// clean up the service store
|
|
120
|
-
service_store_1.serviceStore.clear();
|
|
121
|
-
}
|
|
122
113
|
});
|
|
123
114
|
}
|
|
124
115
|
/**
|
|
@@ -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;
|