Class factory in nestjs

Viewed 468

I want to create a factory service, that will build a new class instance based on parameters. The issue that this child class needs to use another service.

For now, I build it like this.

class Client {
  constructor (params: Params, es: ExternalService){
  }
}

@Module({imports: [ExternalService]})
export class ClientFactory {
  constructor(es: ExternalService)
  build (params: Params) {
    return new Client(params, es);  
  }
}

In this case Client is out of the nest environment. How to do it in more nest way?

0 Answers
Related