Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Providers omitted from SqsModuleAsyncOptions #80

Open
rbonestell opened this issue May 7, 2024 · 0 comments
Open

Providers omitted from SqsModuleAsyncOptions #80

rbonestell opened this issue May 7, 2024 · 0 comments

Comments

@rbonestell
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant