I want to initialize the SqsModule with my config provider and my custom logger instance.
In order to do this, I can use imports with the NestJS ConfigModule... but to inject the Logger as a provider does not work because in the SqsModuleAsyncOptions definition only imports was "picked" from ModuleMetadata: https://github.com/ssut/nestjs-sqs/blob/master/lib/sqs.types.ts#L34
As a workaround, I created a simple module to export the logger, then added that module to my SqsModule registration and it works as expected:
import { Module, Logger } from '@nestjs/common';
@Module({
providers: [Logger],
exports: [Logger],
})
export class SqsLoggerModule { }
usage:
SqsModule.registerAsync({
imports: [ConfigModule, SqsLoggerModule],
useFactory: (configService: ConfigService, logger: Logger) => {
const region = configService.get('AWS.DEFAULT_REGION');
const queueUrl = configService.get('AWS.JOBS_QUEUE_URL');
return {
consumers: [
{
name: 'JobsInbound',
region,
queueUrl,
logger
}
],
};
},
inject: [ConfigService],
}),
Is there any reason proivders was omitted from the registration of the SqlModule? If we could access providers in SqsModuleAsyncOptions then there wouldn't be any need for boilerplate module code to inject providers such as Logger.
I want to initialize the
SqsModulewith my config provider and my custom logger instance.In order to do this, I can use
importswith the NestJSConfigModule... but to inject theLoggeras aproviderdoes not work because in theSqsModuleAsyncOptionsdefinition onlyimportswas "picked" fromModuleMetadata: https://github.com/ssut/nestjs-sqs/blob/master/lib/sqs.types.ts#L34As a workaround, I created a simple module to export the logger, then added that module to my
SqsModuleregistration and it works as expected:usage:
Is there any reason
proivderswas omitted from the registration of theSqlModule? If we could accessprovidersinSqsModuleAsyncOptionsthen there wouldn't be any need for boilerplate module code to inject providers such asLogger.