@travetto/di 8.0.0-alpha.1 → 8.0.0-alpha.10

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/README.md CHANGED
@@ -268,7 +268,7 @@ class Service {
268
268
  ```
269
269
 
270
270
  ## Manual Invocation
271
- Some times you will need to lookup a dependency dynamically, or you want to control the injection process at a more granular level. To achieve that you will need to directly access the [DependencyRegistryIndex](https://github.com/travetto/travetto/tree/main/module/di/src/registry/registry-index.ts#L16). The registry allows for requesting a dependency by class reference:
271
+ Some times you will need to lookup a dependency dynamically, or you want to control the injection process at a more granular level. To achieve that you will need to directly access the [DependencyRegistryIndex](https://github.com/travetto/travetto/tree/main/module/di/src/registry/registry-index.ts#L17). The registry allows for requesting a dependency by class reference:
272
272
 
273
273
  **Code: Example of Manual Lookup**
274
274
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/di",
3
- "version": "8.0.0-alpha.1",
3
+ "version": "8.0.0-alpha.10",
4
4
  "type": "module",
5
5
  "description": "Dependency registration/management and injection support.",
6
6
  "keywords": [
@@ -28,10 +28,10 @@
28
28
  "directory": "module/di"
29
29
  },
30
30
  "dependencies": {
31
- "@travetto/registry": "^8.0.0-alpha.1"
31
+ "@travetto/registry": "^8.0.0-alpha.10"
32
32
  },
33
33
  "peerDependencies": {
34
- "@travetto/transformer": "^8.0.0-alpha.1"
34
+ "@travetto/transformer": "^8.0.0-alpha.5"
35
35
  },
36
36
  "peerDependenciesMeta": {
37
37
  "@travetto/transformer": {
@@ -8,6 +8,7 @@ import { InjectionError } from '../error.ts';
8
8
  import { DependencyRegistryResolver } from './registry-resolver.ts';
9
9
 
10
10
  const MetadataSymbol = Symbol();
11
+ const PostConstructionRan = Symbol();
11
12
 
12
13
  function readMetadata(item: { metadata?: Record<symbol, unknown> }): Dependency | undefined {
13
14
  return castTo<Dependency | undefined>(item.metadata?.[MetadataSymbol]);
@@ -166,10 +167,11 @@ export class DependencyRegistryIndex implements RegistryIndex {
166
167
  // And auto-wire fields
167
168
  await this.injectFields(targetType, instance, candidate.class);
168
169
 
169
- // Run post constructors if output is not already as a dependency
170
- const isParameterTargetType = params.find(param => typeof param === 'object' && param !== null && param.constructor === targetType);
170
+ // Run post constructors if not run yet
171
+ const constructed: T & { [PostConstructionRan]?: boolean } = instance!;
172
+ if (!constructed[PostConstructionRan]) {
173
+ constructed[PostConstructionRan] = true;
171
174
 
172
- if (!isParameterTargetType) {
173
175
  // Run post constructors
174
176
  const postConstruct = this.store.has(targetType) ? this.getConfig(targetType).postConstruct : [];
175
177
  for (const { operation } of postConstruct) {