-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Transient and Request scopes do not work together #3303
Comments
Fixed in 6.9.0 |
Hi @kamilmysliwiec. Since 6.9.0 the following request-scoped service doesn't work anymore. @Injectable({ scope: Scope.REQUEST })
export class ApiAuthenticatedUserProvider implements UserProvider {
constructor(@Inject(REQUEST) private readonly request: express.Request) {
console.log('!!!!!', { request });
}
get user(): ApiUser {
return xxxxxxx(this.request.user);
}
} => Registration happens via When reverting to |
@ulrichb if you use custom providers syntax ( |
@kamilmysliwiec: Okay thanks, this fixes my problem. But why isn't it inferred from the decorator (as it seems to be in <= 6.8.5). Further it's a bit annoying to duplicate the scope information (also error prune when when doing refactorings). |
Also note that I'm using |
I'll push another fix shortly (to make it more straightforward :)) |
Okay cool. BTW: If not inferred from the decorator Nest should at least warn about a "mismatching" scope value when using |
@kamilmysliwiec Did you already have a look at this? Or should I create a new issue for my " |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Current behavior
If the application has both
transient
andrequest
scopes, thetransient
scoped service does not work. The services/controllers that use thetransient
service does not have the correct instance of thetransient
serviceInput Code
Minimum reproducible repo
code to run.
LoggerService
is a transient serviceContextService
is a request serviceThe
LoggerService
is an empty object when a request comes in. Everything initialized theconstructor
is gone. Services/Controllers are not using the same instance that was created.If either scope is removed, then both services work correctly according to its scope. It is only when there are transient and request scopes, then the transient scopes class won't work.
Some code snippets:
Expected behavior
The
LoggerService
instances should have used the one that was created instead of an empty object while in the request scope.Possible Solution
Environment
The text was updated successfully, but these errors were encountered: