Hello,
I have the following module:
@Module({
providers: [
MyStaticService,
LoggingService
]
})
export class MyModule {}
I want to dynamically load in a class (MyDynamicService) at runtime, to do this I plan on using ModuleRef.
I have the following code:
class MyStaticService {
constructor(private readonly moduleRef: ModuleRef) {}
async doSomething() {
await this.moduleRef.create(MyDynamicService);
}
}
This works, however, MyDynamicService is instantiated without any dependencies.
@Injectable()
class MyDynamicService {
constructor(logger: LoggingService) {
logger.info('hello'); // TypeError: info is not property on undefined
}
}
What am I doing wrong here? How can I get ModuleRef.create() to also handle injecting the logger?
Thanks!