NestJS · Senior · Question 7 of 75
How can you discover all providers with a custom decorator at startup, e.g. to register event handlers automatically?
- ✓Correct answer: Use
DiscoveryServicewithcreateDecoratorto find decorated providers or methods and wire them up inonModuleInit - 2Read the
srcfolder withfsat runtime - 3Nest can't do this
Explanation
Libraries like @nestjs/cqrs and @nestjs/schedule use the same scanning mechanism.