Skip to content

Providers omitted from SqsModuleAsyncOptions #80

@rbonestell

Description

@rbonestell

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions