ts-ioc-container 32.4.0 → 32.5.0

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.
Files changed (2) hide show
  1. package/README.md +6 -13
  2. package/package.json +2 -2
package/README.md CHANGED
@@ -1141,13 +1141,13 @@ import {
1141
1141
  constructor,
1142
1142
  Container,
1143
1143
  key,
1144
- getHooks,
1145
1144
  hook,
1146
1145
  IContainer,
1147
1146
  IInjector,
1148
1147
  MetadataInjector,
1149
1148
  Registration as R,
1150
1149
  register,
1150
+ executeHooks,
1151
1151
  } from 'ts-ioc-container';
1152
1152
  import { InjectOptions } from '../lib/injector/IInjector.ts';
1153
1153
 
@@ -1156,11 +1156,7 @@ class MyInjector implements IInjector {
1156
1156
 
1157
1157
  resolve<T>(container: IContainer, value: constructor<T>, options: InjectOptions): T {
1158
1158
  const instance = this.injector.resolve(container, value, options);
1159
- // eslint-disable-next-line @typescript-eslint/ban-types
1160
- for (const [h] of getHooks(instance as object, 'onConstruct')) {
1161
- // @ts-ignore
1162
- instance[h]();
1163
- }
1159
+ executeHooks(instance as object, 'onConstruct', { scope: container });
1164
1160
  return instance;
1165
1161
  }
1166
1162
  }
@@ -1169,7 +1165,7 @@ class MyInjector implements IInjector {
1169
1165
  class Logger {
1170
1166
  isReady = false;
1171
1167
 
1172
- @hook('onConstruct') // <--- or extract it to @onConstruct
1168
+ @hook('onConstruct', (context) => context.invokeMethod({ args: [] })) // <--- or extract it to @onConstruct
1173
1169
  initialize() {
1174
1170
  this.isReady = true;
1175
1171
  }
@@ -1206,6 +1202,7 @@ import {
1206
1202
  Registration as R,
1207
1203
  MetadataInjector,
1208
1204
  register,
1205
+ executeHooks,
1209
1206
  } from 'ts-ioc-container';
1210
1207
 
1211
1208
  @register(key('logsRepo'))
@@ -1228,7 +1225,7 @@ class Logger {
1228
1225
  this.messages.push(message);
1229
1226
  }
1230
1227
 
1231
- @hook('onDispose') // <--- or extract it to @onDispose
1228
+ @hook('onDispose', (c) => c.invokeMethod({ args: [] })) // <--- or extract it to @onDispose
1232
1229
  async save(): Promise<void> {
1233
1230
  this.logsRepo.saveLogs(this.messages);
1234
1231
  this.messages = [];
@@ -1243,11 +1240,7 @@ describe('onDispose', function () {
1243
1240
  logger.log('Hello');
1244
1241
 
1245
1242
  for (const instance of container.getInstances()) {
1246
- // eslint-disable-next-line @typescript-eslint/ban-types
1247
- for (const [h] of getHooks(instance as object, 'onDispose')) {
1248
- // @ts-ignore
1249
- await instance[h]();
1250
- }
1243
+ executeHooks(instance as object, 'onDispose', { scope: container });
1251
1244
  }
1252
1245
 
1253
1246
  expect(container.resolve<LogsRepo>('logsRepo').savedLogs).toContain('Hello');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-ioc-container",
3
- "version": "32.4.0",
3
+ "version": "32.5.0",
4
4
  "description": "Typescript IoC container",
5
5
  "publishConfig": {
6
6
  "access": "public",
@@ -59,5 +59,5 @@
59
59
  "ts-node": "^10.9.1",
60
60
  "typescript": "5.4.3"
61
61
  },
62
- "gitHead": "590a34c13ebc93437a8a368f6e1e39db25600126"
62
+ "gitHead": "464f1f083a81a9346e6a713373be32e204c03238"
63
63
  }