You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When there is a circular dependency, inversify tries to reconstruct the circular path. However, if a multiInject is located in the requests that are evaluated before the actual circular dependencies are reached, inversify assumes the circular dependency there.
Expected Behavior
Inversify correctly identifies the actual circular dependency.
Current Behavior
Inversify blames the multiInject dependency path.
Possible Solution
From my point of view. there seem to be three approaches to tackle this:
Multiple multi-injects appear - for whatever reason - in one dependency chain. Maybe this is how multi-injects are implemented. Either this is a bug that needs to be fixed, or...
...an alternate implementation is found.
alreadyDependencyChain checks if a dependency is already chain only by the service identifier - which is equal for multi injects.
Run with npc ts-node run.ts and see inversify blame the multi-inject for the circular dependency.
Remove the multi-inject from the dependencies, run again, and see inversify show the correct circular path.
Add the multi-inject again, remove the circular dependency and see that the script runs through and there is absolutely no problem with the multi inject.
Context
The error message shown by Inversify is misguiding.
Your Environment
Version used: 6.0.1
Environment name and version (e.g. Chrome 39, node.js 5.4): Node 18.16.0
Operating System and version (desktop or mobile): macOS Ventura
Error: Circular dependency found: Top --> multi-inject --> multi-inject
at /Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/utils/serialization.ts:95:13
at Array.forEach (<anonymous>)
at circularDependencyToException (/Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/utils/serialization.ts:92:25)
at /Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/utils/serialization.ts:97:7
at Array.forEach (<anonymous>)
at circularDependencyToException (/Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/utils/serialization.ts:92:25)
at plan (/Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/planning/planner.ts:246:36)
at /Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/container/container.ts:623:25
at Container._get (/Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/container/container.ts:574:37)
at Container._getButThrowIfAsync (/Users/timvahlbrock/Downloads/tmp3/node_modules/inversify/src/container/container.ts:580:25)
The text was updated successfully, but these errors were encountered:
When there is a circular dependency, inversify tries to reconstruct the circular path. However, if a multiInject is located in the requests that are evaluated before the actual circular dependencies are reached, inversify assumes the circular dependency there.
Expected Behavior
Inversify correctly identifies the actual circular dependency.
Current Behavior
Inversify blames the multiInject dependency path.
Possible Solution
From my point of view. there seem to be three approaches to tackle this:
alreadyDependencyChain
checks if a dependency is already chain only by the service identifier - which is equal for multi injects.Steps to Reproduce (for bugs)
git clone git@github.com:timvahlbrock/inversify-circular-multi-inject.git
cd inversify-circular-multi-inject
npm install
npc ts-node run.ts
and see inversify blame the multi-inject for the circular dependency.Context
The error message shown by Inversify is misguiding.
Your Environment
Stack trace
The text was updated successfully, but these errors were encountered: