Refactor RabbitMQ DI into extension method
Refactored the registration of `RabbitMqConnectionFactory` and RabbitMQ configuration into a new `AddRabbitMqConnectionFactory` extension method for improved modularity and reusability. - Removed direct calls to `AddSingleton<RabbitMqConnectionFactory>` and `Configure<RabbitMqConfiguration>` from the main `DependencyInjection` class. - Added a new static `DependencyInjection` class under the `DigitalData.MessagingService.RabbitMQ` namespace. - The new `AddRabbitMqConnectionFactory` method encapsulates RabbitMQ DI logic and accepts `IServiceCollection` and `IConfiguration` as parameters. - Updated `DependencyInjection.cs` to use the new extension method.
This commit is contained in:
@@ -34,11 +34,9 @@ public static class DependencyInjection
|
||||
// --- Email Queue (RabbitMQ) ---
|
||||
services.AddSingleton<OutgoingEmailConsumer>();
|
||||
services.AddSingleton<IOutgoingEmailPublisher, OutgoingEmailPublisher>();
|
||||
services.AddSingleton<RabbitMqConnectionFactory>();
|
||||
|
||||
// --- RabbitMQ Configuration ---
|
||||
services.Configure<RabbitMqConfiguration>(
|
||||
configuration.GetSection(RabbitMqConfiguration.SectionName));
|
||||
services.AddRabbitMqConnectionFactory(configuration);
|
||||
|
||||
// --- Data Protection (for encryption) ---
|
||||
services.AddDataProtection()
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.MessagingService.RabbitMQ
|
||||
{
|
||||
/// <summary>
|
||||
/// Dependency injection configuration for Infrastructure layer
|
||||
/// </summary>
|
||||
public static class DependencyInjection
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds Infrastructure layer services to the DI container
|
||||
/// </summary>
|
||||
public static IServiceCollection AddRabbitMqConnectionFactory(
|
||||
this IServiceCollection services,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
services.AddSingleton<RabbitMqConnectionFactory>();
|
||||
|
||||
// --- RabbitMQ Configuration ---
|
||||
services.Configure<RabbitMqConfiguration>(
|
||||
configuration.GetSection(RabbitMqConfiguration.SectionName));
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user