The official nest docs on modules explain about global modules and dynamic modules. I'm wondering if it is possible to combine the two patterns?
My use case is the following: I have a dynamic config module:
export class ConfigModule {
static forRoot(baseConfigPath: string): DynamicModule {
const providers = [{ provide: 'Config', useValue: configFactory(baseConfigPath) }];
return {
module: ConfigModule,
providers,
exports: providers,
};
}
}
This enables the config-module to be dependent on the passed in base config path. I can then import the module in the main app module as follows:
@Module({
imports: [ConfigModule.forRoot(path.resolve(__dirname, '../config'))],
controllers: [AppController],
providers: [AppService],
})
export class AppModule implements NestModule {}
which is kind of nice. However, I do have lots of other modules (child modules of the app module, siblings to the config module), where I also want that same instance of the dynamic config module to be injectable. Would be great if I could mark the dynamic ConfigModule somehow as global - or is there another way?
I've already tried making the ConfigModule global with @Global, but that didn't work - here's a super minimal reduced example repo based on the nest starter created by nest new: https://github.com/DeX3/nest-di-playground
ConfigModuleglobal with@Global? - Chau Tran