alphamikle / nest_transact

Simplest transactions support for Nestjs with Typeorm
MIT License
116 stars 20 forks source link

Fix resolving a provider that is injected using forwardRef #20

Closed maxpeterson closed 1 year ago

maxpeterson commented 1 year ago

Hi @alphamikle,

I found an issue when a service is injected using forwardRef for example @Inject(forwardRef(() => CommonService)), in this case Nest fails to find the service with the eror:

Nest could not find CommonService element (this provider does not exist in the current context)

Based on the Nest module-ref docs, it seems that moduleRef.get(Service) is expecting to be called with the class, rather than it's name.

I have created a PR to fix this (a933f8d42a1b4e49e897f467d1c8e4c9f38c06f2) and included a test in the example folder (eaea4cd595b86366b0f80e9c2fcb8a9168ed3ed9).

npm run test failed for me initially, until I added CacheService to the ExampleAppModule.providers (a3ec991263e350e3cc4571f44fd84f8afa96ab46)

Thanks for providing a great library.

alphamikle commented 1 year ago

Hi @maxpeterson,

Nice to hear! Thank you for the PR

ortonomy commented 1 year ago

@alphamikle - can you make this a release, please? It's still in latest release and causes problems

alphamikle commented 1 year ago

Hi @ortonomy! Thank you for noticing me, it seems that in the last time, I've just accepted the PR and update the package but didn't prebuild it ☹️

For now, it's clear - v9.1.1 contains everything from this PR