I'm relatively new to nestJS and ran into a circular dependency with REQUEST Scoped services that got me reading about ModuleRef in nestJS.
I was looking at the documentation where it mentions that resolving the provider by calling it consecutively returns multiple unique instances for this provider.
Now for my use case I only need to call this once so this is not really relevant to me. But I'd like to know when I may have to make these consecutive calls and why we'd need 2 instances of the same provider.
But I'd like to know when I may have to make these consecutive calls and why we'd need 2 instances of the same provider.
That's just the thing, generally you wouldn't need to have two instances, but the specific documentation you're looking at is regarding TRANSIENT
scoped providers, which are different at every point the are injected, that is, each instance should be unique, which is exactly what the documentation is showing here. It then goes to show that if you need the same instance, you should use a constant for the contextId
passed to ModuleRef#resovle
to ensure that you get the same instance that your resolved earlier