-
Notifications
You must be signed in to change notification settings - Fork 2k
docs: clarify lifecycle events #3281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I stumbled upon this in https://www.mrnice.dev/posts/nestjs-lifecycle/ and it confused me and my teammates. Thought it would be useful to clarify this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I'm following. This hook is called one time only per each provider that implements it. The change you suggested ("not necessarily one time only") may lead someone to think that it might be called several times for the same provider (which isn't true). Correct me if I'm wrong
@magoogli
magoogli
Jul 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kamilmysliwiec I have had the same issue - I have a situation where the hook is called twice for the same provider. This scenario is easily reproduced. See https://github.com/magoogli/nest-js for a minimal repo. Is this expected behaviour? My onModuleInit hook is called twice for the same provider ( although the constructor is only called once ). This is very confusing and frustrating. Any help would be greatly appreciated.
I stumbled upon this in https://www.mrnice.dev/posts/nestjs-lifecycle/ and it confused me and my teammates. Thought it would be useful to clarify this
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
This is my first contrib to NestJS - tried to follow the guidelines, hoping I didn't miss anything. This was just a docs change so just did everything as quickly as possible from the web interface on GitHub