You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
I was having an issue where a module (BankIdModule) needed an instance of HttpModule with a custom Agent configured with specific certificates.
These needed to be configurable from the BankIdModule, so I needed to be able to pass the options from the BankIdModule to the HttpModule. solving the register property of my DynamicModule was easy enough, but I was having a hard time with the registerAsync method. I read docs, check out the advanced concepts course section on Dynamic modules, Asked CoPilot, and ChatGPT 4o.
Finally with the help of brendonmfo on discord, it was solved with the extraProviders property that you can set on the HttpModule.registerAsync call. I couldn't find any documentation on this property. and all the solutions involved creating intermediate providers that you registered before registering the BankIdModule etc.
In order to pass options from your module, to any imported module in it, you can use the extraProviders property to pass your modules providers to the imported module.
import{Module}from'@nestjs/common';import{ASYNC_OPTIONS_TYPE,ConfigurableModuleClass,OPTIONS_TYPE,}from'./config.module-definition';import{ConfigService}from'./config.service';import{HttpModule}from'@nestjs/axios';
@Module({providers: [ConfigService],exports: [ConfigService],})exportclassConfigModuleextendsConfigurableModuleClass{staticregister(options: typeofOPTIONS_TYPE): DynamicModule{return{// your custom logic here
...super.register(options),};}staticregisterAsync(moduleOptions: typeofASYNC_OPTIONS_TYPE): DynamicModule{const{imports, providers, exports}=super.registerAsync(moduleOptions);return{imports: [...(imports??[]),HttpModule.registerAsync({useFactory: (options: typeofOPTIONS_TYPE)=>{// your modules OPTIONS_TYPE is now availablereturn{};},inject: [CONFIG_MODULE_OPTIONS],extraProviders: providers,// <-- Pass the returned `providers` property from the `super` call above})],
providers,
exports
};}}
What is the motivation / use case for changing the behavior?
This is an undocumented API that would help when you need to pass configurations to internal submodules.
The text was updated successfully, but these errors were encountered:
Is there an existing issue that is already proposing this?
Is your feature request related to a problem? Please describe it
I was having an issue where a module (
BankIdModule
) needed an instance ofHttpModule
with a customAgent
configured with specific certificates.These needed to be configurable from the
BankIdModule
, so I needed to be able to pass the options from theBankIdModule
to theHttpModule
. solving theregister
property of myDynamicModule
was easy enough, but I was having a hard time with theregisterAsync
method. I read docs, check out theadvanced concepts
course section on Dynamic modules, Asked CoPilot, and ChatGPT 4o.Finally with the help of
brendonmfo
on discord, it was solved with theextraProviders
property that you can set on theHttpModule.registerAsync
call. I couldn't find any documentation on this property. and all the solutions involved creating intermediate providers that you registered before registering theBankIdModule
etc.Discord Thread: https://discord.com/channels/520622812742811698/1241198797065818273
Describe the solution you'd like
A section in the
dynamic modules
article that talks about this property, and how to use it.https://docs.nestjs.com/fundamentals/dynamic-modules#extending-auto-generated-methods
Teachability, documentation, adoption, migration strategy
In order to pass options from your module, to any imported module in it, you can use the
extraProviders
property to pass your modules providers to the imported module.What is the motivation / use case for changing the behavior?
This is an undocumented API that would help when you need to pass configurations to internal submodules.
The text was updated successfully, but these errors were encountered: