Hi! I've been following official documentation about Dynamic modules and I headed head first into a wall when it came to registerAsync.
The goal of my is to return a module where the @golevelup/nestjs-rabbitmq module is setup with all it's routes and services, provided that the rabbitmq is present in the application configuration.
Let's break it into pieces:
Here is what the MessagingModule looks like:
@Module({})
export class MessagingModule extends ConfigurableModule{
static register(options: typeof OPTION_TYPE): DynamicModule{
if(options.active) return null;
return {module: MessagingCoreModule}
}
}
}
For all intense and purpose, this is how I defined the ConfigurableModule and the options:
export interface MessagingOptions{
active: boolean
}
export interface MessagingModuleFactory{
createMessagingOptions: () => MessagingOptions | Promise<MessagingOptions>
}
export const {ConfigurableModuleClass, OPTION_TYPE, ASYNC_OPTION_TYPE} = new ConfigurableOptionModuleBuilder<MessagingOptions>().setFactoryMethodName('createMessagingOptions').build()
Now, to my issue, the registerAsync function's options are as follows: imports, inject, useClass, useInstance, useFactory. I don't see a way to have access to the {active: boolean} property provided by one of the factories.
@Module({})
export class MessagingModule extends ConfigurableModule{
static register(options: typeof OPTION_TYPE): DynamicModule{
if(options.active) return null;
return {module: MessagingCoreModule}
}
}
}
statis async registerAync(options: typeof ASYNC_OPTIONS_TYPE){
...
// How do I access options.active here?
}
How should this function look like to have the same outcome as register using the provided options by the async factories?