'Proper way to export dynamic module
I have a NestJS application with the CoreModule
which exports an collection of the core services to all other modules.
In core module i have dynamic module register HttpModule
.
I won't to register this module twice for import and export so i do the following:
const httpModule = HttpModule.register({
timeout: Configuration.requestTimeoutMilliseconds
});
@Module({
imports: [httpModule],
providers: [
...
],
exports: [
httpModule,
...
]
})
export class CoreModule { }
When i start my app i see in InstanceLoader
logs HttpModule
dependencies registered twice:
What the proper way to export dynamic modules in general?
Solution 1:[1]
You can do it like this.
@Module({
imports: [
HttpModule.register({
timeout: Configuration.requestTimeoutMilliseconds,
}),
],
providers: [],
exports: [HttpModule],
})
export class CoreModule {}
Makes sense to me because when you want to implement a dynamic module, you need to return module class as a module identifier in the module field.
There are examples of declaring dynamic modules on this page in documentation https://docs.nestjs.com/fundamentals/dynamic-modules#module-configuration
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Danylo Fedorov |