Papooch / nestjs-cls

A continuation-local storage (async context) module compatible with NestJS's dependency injection.

Home Page:https://papooch.github.io/nestjs-cls/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't resolve HttpService

justinpenguin45 opened this issue · comments

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

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.

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

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 🤔

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.

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

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