NestJS · Middle · Question 18 of 75
How do you resolve a circular dependency between two providers?
- 1Make both providers global
- 2Nest resolves cycles automatically without changes
- ✓Correct answer: Prefer refactoring; if needed, use
forwardRef(() => OtherService)with@Inject()on both sides
Explanation
Cycles usually mean responsibilities are mixed. Extracting the shared logic into a third provider is the cleaner fix.