The diagram does a good job at explaining the flow I currently have and why that is failing.

  • I have logger.module that exports a loger.service that depends on a @nestjs/mongoose LogModel.
  • I have a db.module that exports session.service and imports logger.module.
  • I have a session.service that is exported by the Db.Module and imports logger.service
  • I have a mock.db.module that is exactly like the real db.module (no mocked services, the real one) except the mongoose connection is to a in-memory mongodb.
  • I have a session.service.spec tests file that imports mock.db.module

However, I can't find any good way of providing LogModelinto log.module that doesn't need me to import @nestjs/mongooseand instantiate/wait for a new connection on every startup.

I was only able to produce 2 results:

  • use @forwardRef(() => Logger.module.register()) or/and @forwardRef(()=> Db.module.register()) which causes heap allocation error
  • don't use forwardRef and get circular dependency warnings.

How can I effectively map dependencies in an efficient way with Nestjs for this use case?

Diagram:

enter image description here

0

There are 0 answers