32 lines
1.1 KiB
C#
32 lines
1.1 KiB
C#
using System;
|
|
using System.Linq;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Svrnty.CQRS.Events.Abstractions.Subscriptions;
|
|
|
|
namespace Svrnty.CQRS.Events.PostgreSQL.Subscriptions;
|
|
|
|
/// <summary>
|
|
/// Service collection extensions for PostgreSQL subscription storage.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Add PostgreSQL subscription store to the service collection.
|
|
/// Replaces any existing ISubscriptionStore registration.
|
|
/// </summary>
|
|
public static IServiceCollection AddPostgresSubscriptionStore(this IServiceCollection services)
|
|
{
|
|
// Remove existing IPersistentSubscriptionStore registration (e.g., in-memory)
|
|
var descriptor = services.FirstOrDefault(d => d.ServiceType == typeof(IPersistentSubscriptionStore));
|
|
if (descriptor != null)
|
|
{
|
|
services.Remove(descriptor);
|
|
}
|
|
|
|
// Register PostgreSQL implementation
|
|
services.AddSingleton<IPersistentSubscriptionStore, PostgresSubscriptionStore>();
|
|
|
|
return services;
|
|
}
|
|
}
|