nestjs-cls icon indicating copy to clipboard operation
nestjs-cls copied to clipboard

Add proper support for injecting proxy providers into other proxy providers

Open Papooch opened this issue 1 year ago • 0 comments

Currently, only the built-in CLS_REQ and CLS_RES proxy providers are able to be injected in other proxy providers.

There is only a partial support for injecting custom proxy providers with some manual work by calling await cls.resolveProxyProviders(TheOtherProvider) in proxy provider factories when they depend on other proxy providers and their value is needed at the time of construction.

There is no support for this workflow in class proxy providers, because the constructor must be synchronous, but resolving proxy providers is an asynchronous operation.


Solution: when resolving proxy providers, scan their dependency array for other proxy providers and resolve those first. That should ensure that dependent proxy providers are always resolved when needed in other proxy providers.

Papooch avatar Jul 26 '24 16:07 Papooch