Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!