-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
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
Global module provider injection issue #4873
Comments
There are several workarounds:
|
Any updates on this? I am running into a similar issue. |
Hey guys, I'm facing same issue when using Request Scoped Provider even not directly in Global Guard. Constructor of this Global Guard is not called and canActivate method throwing errors because DI is not working. I need Request Scoped Provider to gather temporary data from request. If there is another way to do this, until issue is fixed - LMK. (Param decorator is not a solution in my case) |
nestjs/graphql#325 may have a solution you're looking for, using |
If in NestJS DI works similarly to Angular DI, then the injectors are connected by a hierarchical connection. Therefore, from the lower scope (request) you can ask providers from the higher scope (application), but not vice versa. As far as I understand, you are trying to get from the application scope the request scope. Yes? If so, then of course you need:
And you can remove request scope from X provider. |
I also faced the same error. so i'm using |
As @KostyaTretyak mentions, the dependency injection hierarchy means that you will need to add an import statement in I can reproduce your error from your input code, and resolve it by adding
|
Bug Report
Current behavior
The issue arises in the following setup:
AppModule
importsModuleA
(global) andModuleB
(non-global) andConfigModule.forRoot
,ModuleA
declares someREQUEST
-scoped providerX
with request context being injected,ModuleB
importsConfigModule.forFeature
, and declares some providerY
, without specifying a scope, withX
and config being injected.In such setup constructor for
X
injected intoY
is not called (in caseX
is declared using class).If
X
is declared viauseFactory
,null
is injected intoY
.Input Code
https://github.com/zyulyaev/nest-global-module-issue
Expected behavior
X
's constructor is called and its dependencies are injected.Environment
The text was updated successfully, but these errors were encountered: