Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.
https://papooch.github.io/nestjs-cls/
MIT License
433 stars 28 forks source link

Can't resolve HttpService #65

Closed justinpenguin45 closed 1 year ago

justinpenguin45 commented 1 year ago

I have a service which has a dependency on HttpService from nestjs HttpModule. This was working fine and being injected until I gave the class the @InjectableProxy attribute. Now I get this error

Cannot create Proxy provider RequestScopedService (?, RequestHelper). The argument HttpService at index [0] was not found in the ClsModule Context.

Potential solutions: - If HttpService is a provider from a separate module, make sure to import the module in "ClsModule.forFeatureAsync()" registration

justinpenguin45 commented 1 year ago

Attempted to fix it by adding this on my Module imports - didnt help.

ClsModule.forFeatureAsync( {imports: [HttpModule], useClass: HttpService})

I get this error

Cannot create a Proxy provider for HttpService. The class must be explicitly decorated with the @InjectableProxy() decorator to distinguish it from a regular provider.

justinpenguin45 commented 1 year ago

Tried this as well, since the RequestScopedService is what has the dependency on HttpService

ClsModule.forFeatureAsync( {imports: [HttpModule], // now you can inject DogsService in the DogContext Proxy Provider useClass: RequestScopedService})

I get this error

Cannot create Proxy provider RequestScopedService (?, RequestHelper). The argument HttpService at index [0] was not found in the ClsModule Context.

Potential solutions: - If HttpService is a provider from a separate module, make sure to import the module in "ClsModule.forFeatureAsync()" registration

Papooch commented 1 year ago

I believe HttpModule is dynamic, do you need to put

HttpModule.register()

in the imports.

If that does not help, please provide a minimal repoducible example, so I can investigate.

EDIT: actually HttpModule can be used also with a static import, so this should actually work :thinking:

Papooch commented 1 year ago

I just tried it in the library's test suite and it works as expected image

So I would again like to ask you for a working example in which you demonstrate the problem you're having.

Papooch commented 1 year ago

@justinpenguin45 Did you manage to solve your problem on your side, or do you require more assistance?

Papooch commented 1 year ago

I'm going to assume the issue is solved or no longer relevant, feel free to open a new one when problems arise.