Add Action<RabbitMqConfiguration> overload to RabbitMQ DI registration

This commit is contained in:
2026-07-28 14:33:36 +02:00
parent 7f55d97352
commit a38e8f9680

View File

@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
namespace DigitalData.MessagingService.RabbitMQ
{
@@ -8,14 +9,31 @@ namespace DigitalData.MessagingService.RabbitMQ
/// </summary>
public static class DependencyInjection
{
private static IServiceCollection AddDefaultServices(this IServiceCollection services)
{
services.AddSingleton<RabbitMqConnectionFactory>();
return services;
}
/// <summary>
/// Adds Infrastructure layer services to the DI container
/// </summary>
public static IServiceCollection AddRabbitMqConnectionFactory(
this IServiceCollection services,
IConfiguration configuration)
public static IServiceCollection AddRabbitMqConnectionFactory(this IServiceCollection services, Action<RabbitMqConfiguration> configure)
{
services.AddSingleton<RabbitMqConnectionFactory>();
services.AddDefaultServices();
// --- RabbitMQ Configuration ---
services.Configure(configure);
return services;
}
/// <summary>
/// Adds Infrastructure layer services to the DI container
/// </summary>
public static IServiceCollection AddRabbitMqConnectionFactory(this IServiceCollection services, IConfiguration configuration)
{
services.AddDefaultServices();
// --- RabbitMQ Configuration ---
services.Configure<RabbitMqConfiguration>(
@@ -24,5 +42,4 @@ namespace DigitalData.MessagingService.RabbitMQ
return services;
}
}
}