Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
How to instance a constructor with dynamic argument in a responsible DI way

I'm trying to instance a service with arguments when using the payload received. Ideally I'd like to do this in a more controlled DI responsible way but not sure of the correct approach. Ref code:

// inside controller
public async handleRequest(
  @Body() requestDto: RequestDTO
): Promise<void> {
  this.newService = new NewService(
    API_KEYS.get(requestDto.address.country)
  );
  
  await this.newService.triggerBoarding(requestDto);
}

This means the service I use in my NewService also has to know about the argument:

constructor(apiKey: string) {
  this.outletService = new OutletService(apiKey);
}

Would this be a case for lazy loading and using moduleRef?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda