#Ability to access providers from DI while constructing a dynamic module

2 messages · Page 1 of 1 (latest)

fluid wren
#

HI! Perhaps someone will tell you how you can make dynamic imports in the module that depend on the value in "ConfigService"?

I found the following https://github.com/nestjs/nest/issues/10151 and https://github.com/nestjs/docs.nestjs.com/issues/223 , but I still don't understand.

Example:

@Module({ controllers: [ControllerA] })
class AModule {}

@Module({ controllers: [ControllerB] })
class BModule {}

@Module({})
class BaseModule {
    static forRootAsync(...) {
        // Get the value from `configService`
        const module = configService.get('module')

        if (module === 'a') return { imports: [AModule] };

        return { imports: [BModule] };
    }
}

// Usage
class AppModule {
     imports: [BaseModule.forRootAsync(…)]
}
GitHub

Is there an existing issue that is already proposing this? I have searched the existing issues Is your feature request related to a problem? Please describe it Reopening #9046 because it wasn&#...

GitHub

I'm submitting a... [ ] Regression [ ] Bug report [ ] Feature request [x] Documentation issue or request (new chapter/page) [ ] Support request => Please do not submit support reques...

harsh jacinth
#

is your example working or what? I didn't follow