NestJS · Senior · Question 10 of 75
Why might an injected value be undefined inside a constructor but defined later, with circular dependencies?
- 1Constructors run after
onModuleInit - 2Nest injects lazily by default for all providers
- ✓Correct answer: With
forwardRef, one side may be created before the other is ready; access it after init (e.g. inonModuleInit), not in the constructor
Explanation
Avoid doing work in constructors that depends on other providers' state.