Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
TheCoreMan wants to merge 1 commit into nestjs:master
base: master
Choose a base branch
Loading
from TheCoreMan:patch-1

Conversation

Copy link

@TheCoreMan TheCoreMan commented Jun 15, 2025

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?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Docs
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

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

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
@@ -18,7 +18,7 @@ In the following table, `onModuleDestroy`, `beforeApplicationShutdown` and `onAp

| Lifecycle hook method | Lifecycle event triggering the hook method call |
| ------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onModuleInit()` | Called once the host module's dependencies have been resolved. |
| `onModuleInit()` | Called once the host module's dependencies have been resolved. "Once" meaning called AFTER the host module's dependencies have been resolved, but not necessarily one time only. |
Copy link
Member

@kamilmysliwiec kamilmysliwiec Jun 16, 2025

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

micalevisk reacted with thumbs up emoji
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@kamilmysliwiec kamilmysliwiec kamilmysliwiec left review comments

+1 more reviewer

@magoogli magoogli magoogli left review comments

Reviewers whose approvals may not affect merge requirements
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /