Files
DigitalData.MessagingService/src/infrastructure/DigitalData.MessagingService.Infrastructure/MessagingServiceInfrastructureConfiguration.cs
TekH 5944823155 refactor(infrastructure): introduce MessagingServiceInfrastructureConfiguration builder
Replace the IConfiguration parameter on AddInfrastructure() with a builder
that makes RabbitMQ wiring explicit and validated.

- Add MessagingServiceInfrastructureConfiguration exposing
  AddRabbitMqConnectionFactory() with IConfiguration and Action<T> overloads
- EnsureRabbitMqConnectionFactoryAdded() throws at registration time if the
  caller omits the wiring step
- Remove the implicit services.AddRabbitMqConnectionFactory(configuration)
  call from AddInfrastructure(); callers must opt in via the builder
2026-11-02 15:02:17 +01:00

41 lines
1.4 KiB
C#

using DigitalData.MessagingService.RabbitMQ;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.MessagingService.Infrastructure;
public class MessagingServiceInfrastructureConfiguration
{
internal IServiceCollection Services { get; }
private bool _rabbitMqConnectionFactoryAdded = false;
internal MessagingServiceInfrastructureConfiguration(IServiceCollection services)
{
Services = services;
}
public void EnsureRabbitMqConnectionFactoryAdded()
{
if (!_rabbitMqConnectionFactoryAdded)
{
throw new InvalidOperationException("RabbitMQ connection factory has not been added. Please call AddRabbitMqConnectionFactory() before using this configuration.");
}
}
public MessagingServiceInfrastructureConfiguration AddRabbitMqConnectionFactory(Action<RabbitMqConfiguration> configure)
{
Services.AddRabbitMqConnectionFactory(configure);
_rabbitMqConnectionFactoryAdded = true;
return this;
}
public MessagingServiceInfrastructureConfiguration AddRabbitMqConnectionFactory(IConfiguration configuration, string sectionName = RabbitMqConfiguration.SectionName)
{
Services.AddRabbitMqConnectionFactory(configuration, sectionName);
_rabbitMqConnectionFactoryAdded = true;
return this;
}
}