If there is a circular dependency on symbols and @inject is called with undefined, error is thrown too late — during dependency resolution from container (container.get).
Expected Behavior
Inversify should early realize that undefined is injected and throw an error. There should be a possibility to provide a function that would lazily return symbol which solves the problem of circular dependency.
My real problem is that the error is thrown too late. This bug slipped through all my tests (both unit and integration) and was triggered only when the user would click the specific button in my application (we use inversify with react) which would kick action with few dependencies resolved by inversify.
If there is a circular dependency on symbols and
@inject
is called withundefined
, error is thrown too late — during dependency resolution from container (container.get
).Expected Behavior
Inversify should early realize that
undefined
is injected and throw an error. There should be a possibility to provide a function that would lazily return symbol which solves the problem of circular dependency.Current Behavior
The error is thrown but too late. Related: https://github.com/inversify/InversifyJS/issues/685
Possible Solution
https://github.com/inversify/InversifyJS/blob/master/src/annotation/inject.ts#L7 here on before returning function should be a guard check for undefined. I don't believe that anyone would inject
undefined
on purpose. The final solution would be to allow using function lazily returning symbol.Steps to Reproduce (for bugs)
repro
Context
My real problem is that the error is thrown too late. This bug slipped through all my tests (both unit and integration) and was triggered only when the user would click the specific button in my application (we use inversify with react) which would kick action with few dependencies resolved by inversify.
Related: https://github.com/inversify/InversifyJS/issues/685
@remojansen I am happy to work on PR, I just want to discuss possible solutions first.