Hi everybody š
I'm new to NestJS and to this Discord community. It's my understanding that this is the best place to ask questions, but if not, please let me know!
So here goes: I recently opened an issue about issues with circular dependencies and request-scoped providers. You can find the issue here: https://github.com/nestjs/nest/issues/11294
I understand that circular dependencies are an architectural smell and should be avoided and that request-scoped circular dependencies are even worse. That being said, we're looking to migrate a legacy Node.js app to NestJS incrementally so we can't avoid running into situations like these.
Also, I understand the technical challenges with circular dependencies and the non-determinism that's present when it comes to instantiate a provider that has a circular dependency.
That being said, these challenges tend to manifest themselves when relying on an instantiation order in the provider constructors since the constructor of one provider might've run before the other. What I don't understand is why this would impact a controller's method. I would have imagined that when a request comes in NestJS would be able to instantiate all request-scoped providers (in a non-deterministic order, that's ok), and then call the relevant controller methods. Is this just not possible? How come in the issue I linked above this is fixed by having forwardRef in the other direction? It seems that NestJS should be able to handle this without issue but my guess is that I'm missing something or misunderstanding how NestJS instantiates providers during a request and how that affect controller method calls. I would really appreciate if somebody familiar with NestJS internals could shed some light here šø