namespace HrynCo.NotificationService.Worker; using HrynCo.NotificationService.Contracts.Messages; using Hrynco.RabbitMq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using HrynCo.NotificationService.Worker.Services.EmailProcessing; public sealed class SendEmailConsumer : RabbitMqConsumerBase { private readonly IServiceScopeFactory _scopeFactory; public SendEmailConsumer( IOptionsMonitor options, IServiceScopeFactory scopeFactory, ILogger logger) : base(options, logger) { _scopeFactory = scopeFactory; } private const string IncomingQueue = "notification.send-email"; protected override string QueueName => IncomingQueue; protected override async Task HandleMessageAsync(SendEmailMessage message, CancellationToken cancellationToken) { using var scope = _scopeFactory.CreateScope(); var service = scope.ServiceProvider.GetRequiredService(); await service.ProcessAsync(message, cancellationToken); } }