From 3a21b3ba9489838b8eb6c71c644a1e78df01764c Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 17 Nov 2026 20:22:50 +0100 Subject: [PATCH] Improve RabbitMQ configuration handling in DI setup Refactor the `DependencyInjection` class to enhance the validation and setup process for `RabbitMQ` when used as the `ConsumerType`. Remove the outdated logic for adding an HTTP client based on `options.ApiUrl`. Introduce a check for `options.RabbitMQ` and throw a detailed `InvalidOperationException` if it is missing. Use `services.AddMessagingServiceClient` to configure the messaging service client with the appropriate section name. --- .../DependencyInjection.cs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/EnvelopeGenerator.Infrastructure.Notification/DependencyInjection.cs b/EnvelopeGenerator.Infrastructure.Notification/DependencyInjection.cs index 192c688d..77250af8 100644 --- a/EnvelopeGenerator.Infrastructure.Notification/DependencyInjection.cs +++ b/EnvelopeGenerator.Infrastructure.Notification/DependencyInjection.cs @@ -31,15 +31,14 @@ public static class DependencyInjection $"MessagingServiceApiUrl must be provided when ClientType is set to Api in the '{sectionName}' configuration section."); break; case ConsumerType.RabbitMQ: - if (options.ApiUrl is string rabbitModeApiUrl) - services.AddMessagingServiceHttpClient(opt => - { - opt.BaseAddress = new Uri(rabbitModeApiUrl); - }); - else + if (options.RabbitMQ is null) throw new InvalidOperationException( - $"Missing API URL configuration." + - $"When ClientType is set to RabbitMQ in an isolated host, Notification:ApiUrl must be provided in the '{sectionName}' configuration section."); + $"Missing RabbitMQ configuration. " + + $"When ConsumerType is set to RabbitMQ, '{sectionName}:{nameof(NotificationOptions.RabbitMQ)}' must be configured."); + + services.AddMessagingServiceClient( + configuration, + rabbitMqConnectionSectionName: $"{sectionName}:{nameof(NotificationOptions.RabbitMQ)}"); break; default: throw new InvalidOperationException(