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

Expose resolveProxyProvider function as we expose resolveProxyProviders

jpamorimdev opened this issue · comments

Is it possible to expose resolveProxyProvider as we expose resolveProxyProviders? It gives us the flexibility of resolving the providers properly when needed.

I had that idea in my mind for a while, too. Do you mean resolving proxy providers individually?

I think it could work if we added an array of proxy provider injection tokens as an array to the resolveProxyProviders method, which would only resolve those that were supplied. If none are passed, then resolve all that have not been resolved yet. Would that work for your use case?

Exactly! That would work perfectly.

const provider1 = 'PROVIDER_1'
const provider2 = 'PROVIDER_2'
const provider3 = 'PROVIDER_3'
const provider4 = 'PROVIDER_4'

// some business logic..
// should resolve only provider1
clsService.resolveProxyProviders([provider1])

// some business logic..
// should resolve only provider2
clsService.resolveProxyProviders([provider2])

// some business logic..
// should resolve all unresolved providers(aka provider3 and provider4)
clsService.resolveProxyProviders()

I think another good improvement together with this would be an options param for resolveProxyProviders where we could pass something like force as boolean and it would ignore the piece of code where it checks if the provider already exists in the CLS it could be useful in some scenarios.

it could be useful in some scenarios

I'm not a fan of adding features unless they solve a concrete problem. Let's start with selective resolution of proxy providers only.

it could be useful in some scenarios

I'm not a fan of adding features unless they solve a concrete problem. Let's start with selective resolution of proxy providers only.

I see, same, just thought as it'll be useful to follow DRY while I add cronjobs that will run for every tenant db but no worries about that for now.

Btw I appreciate the enhancement of resolving proxy providers individually

Released in 4.3.0

Released in 4.3.0

Awesome, thanks for the update!