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
I'm currently struggling with a circular dependency in the validateaction. This issue is half plea for help and half documenting my attempts. I expect the issue to generalize to other JobActions in the future.
Steps to Reproduce
The issue relates to my validateaction-circular branch. Here's the dependency graph, where errors indicate an imports relation between NestJS modules:
CaslService needs to get authorization info from the JobConfigModule. ValidateJobActionModule needs to access the database to retrieve dataset information.
NestJS provides a doc page on circular dependencies which suggests breaking the circle using a forwardRef. This somewhat works in the above branch (the app starts up), but numerous tests fail due to remaining circular dependencies. Adding forwardRef to every import of CaslModule fixes the circular dependency errors, but gives further errors about the database connections not being set up.
Another suggestion from the docs is to use ModuleRef to load the module dynamically. I tried this in the validateaction branch. Tests pass, but the app doesn't start because the DatasetService is not available at runtime in the correct context.
The text was updated successfully, but these errors were encountered:
This is now fixed in #1473. ModuleRef was the correct path, with the DatasetService getting resolved at runtime rather than during dependency injection since DatasetService has REQUEST scope.
Summary
I'm currently struggling with a circular dependency in the validateaction. This issue is half plea for help and half documenting my attempts. I expect the issue to generalize to other JobActions in the future.
Steps to Reproduce
The issue relates to my validateaction-circular branch. Here's the dependency graph, where errors indicate an
imports
relation between NestJS modules:CaslService needs to get authorization info from the JobConfigModule. ValidateJobActionModule needs to access the database to retrieve dataset information.
NestJS provides a doc page on circular dependencies which suggests breaking the circle using a
forwardRef
. This somewhat works in the above branch (the app starts up), but numerous tests fail due to remaining circular dependencies. AddingforwardRef
to every import of CaslModule fixes the circular dependency errors, but gives further errors about the database connections not being set up.Another suggestion from the docs is to use
ModuleRef
to load the module dynamically. I tried this in the validateaction branch. Tests pass, but the app doesn't start because the DatasetService is not available at runtime in the correct context.The text was updated successfully, but these errors were encountered: