Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

406
Visualizações
Nestjs dependency injection order when a module depends on a Mongoose model from @nestjs/mongoose, detailed diagram inside

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

over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda