The diagram does a good job at explaining the flow I currently have and why that is failing.
- I have
logger.module
that exports aloger.service
that depends on a@nestjs/mongoose
LogModel
. - I have a
db.module
that exportssession.service
and importslogger.module
. - I have a
session.service
that is exported by theDb.Module
and importslogger.service
- I have a
mock.db.module
that 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.spec
tests file that importsmock.db.module
However, I can't find any good way of providing LogModel
into log.module
that doesn't need me to import @nestjs/mongoose
and 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: