@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
+ }
@@ -1 +1,5 @@
1
- export declare const Service: () => ClassDecorator;
1
+ interface ServiceDecoratorOptions {
2
+ singleton?: boolean;
3
+ }
4
+ export declare const Service: ({ singleton, }?: ServiceDecoratorOptions) => ClassDecorator;
5
+ export {};
@@ -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
- tsyringe_1.container.registerInstance(target, instance);
9
+ singleton
10
+ ? tsyringe_1.container.registerSingleton(target)
11
+ : tsyringe_1.container.register(target, target);
14
12
  }
15
- return function (...args) {
16
- return instance;
17
- };
13
+ service_store_1.serviceStore.add(target);
18
14
  };
19
15
  };
20
16
  exports.Service = Service;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenofolio/hyper-decor",
3
- "version": "1.0.52",
3
+ "version": "1.0.53",
4
4
  "description": "Project core with utilities and features",
5
5
  "main": "dist/index.js",
6
6
  "author": "zenozaga",