-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Closed
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
The onModuleInit hook is called on an transient service at bootstrap without constructing an instance (aka constructor is not called, DI is not processed) if the service is used in the request scoped Controller.
Minimum reproduction code
https://github.com/albert-mirzoyan/reproducible-transient-init/tree/main
Steps to reproduce
- Uncomment the injection of RequestService in the controller's constructor:
//private readonly requestService: RequestService - (Optional) Decorate the controller with
@Controller({ scope: Scope.REQUEST }) - Restart the application.
Expected behavior
The hook TransientService.onModuleInit() should not be called if the instance is not constructed, and when it is constructed in request scope, the hook will not be called anyway.
NestJS version
11.0.1
Packages versions
"dependencies": {
"@nestjs/common": "^11.0.1",
"@nestjs/core": "^11.0.1",
"@nestjs/platform-express": "^11.0.1",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1"
},Node.js version
22.16.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response
Metadata
Metadata
Assignees
Labels
needs triageThis issue has not been looked intoThis issue has not been looked into