I want to create an instance of a dynamically loaded class trough Nest.js dependency injection service.
In Angular I would use Injector.create
, what would be the equivalent in Nest.js ?
I want to create an instance of a dynamically loaded class trough Nest.js dependency injection service.
In Angular I would use Injector.create
, what would be the equivalent in Nest.js ?
First of all you should get a ModuleRef which references current module, and then use its "get" method to get an instance.
@Injectable()
export class AppletService {
files: FileService;
constructor(
private moduleRef: ModuleRef,
) {
this.files = moduleRef.get(FileService);
}
}