Zum Inhalt springen

Circular Dependencies in NestJs

Circular dependency is a situation where two modules depend on one another.

It is You - It is You

One way to resolve this is to make just one of them depend on the other. So A —> B, and B !—-> A 😁

Another way is to use the forwardRef function provided in NestJs.

ForwarRef(B) inside A-Module
From Module A

ForwardRef(A) inside B-Module
From Module B

This will resolve most circular dependency issues; however, some are stubborn.

So, you need the silver bullet (🤦‍♂️):

Specifically Inject() the exceptional service(s)

Inject the Service with ForwardRef

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert