Nestjs 循环依赖 forwardRef() 缺点

Nestjs Circular dependency forwardRef() drawbacks

Official Circular dependency 说:

A circular dependency occurs when two classes depend on each other. For example, class A needs class B, and class B also needs class A. Circular dependencies can arise in Nest between modules and between providers.

While circular dependencies should be avoided where possible, you can't always do so.

没有使用forwardRef()的原因是什么?

循环依赖通常意味着你有紧密绑定的逻辑和可能不稳定的架构,不允许你扩展。如果你真的不想关心这个,你可以在任何你想要的地方添加 forwardRef ,构造函数和服务,但这可能会导致一些奇怪的、难以解决的错误,并且通常被认为是不好的在 Nest 社区中实践。