The diagram does a good job at explaining the flow I currently have and why that is failing.
- I have
logger.modulethat exports aloger.servicethat depends on a@nestjs/mongooseLogModel. - I have a
db.modulethat exportssession.serviceand importslogger.module. - I have a
session.servicethat is exported by theDb.Moduleand importslogger.service - I have a
mock.db.modulethat is exactly like the realdb.module(no mocked services, the real one) except the mongoose connection is to a in-memory mongodb. - I have a
session.service.spectests file that importsmock.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:
