-
Notifications
You must be signed in to change notification settings - Fork 58
Description
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
.