56 lines
2.1 KiB
C#
56 lines
2.1 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using StellaOps.Infrastructure.Postgres;
|
|
using StellaOps.Infrastructure.Postgres.Options;
|
|
using StellaOps.Notify.Storage.Postgres.Repositories;
|
|
|
|
namespace StellaOps.Notify.Storage.Postgres;
|
|
|
|
/// <summary>
|
|
/// Extension methods for configuring Notify PostgreSQL storage services.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds Notify PostgreSQL storage services.
|
|
/// </summary>
|
|
/// <param name="services">Service collection.</param>
|
|
/// <param name="configuration">Configuration root.</param>
|
|
/// <param name="sectionName">Configuration section name for PostgreSQL options.</param>
|
|
/// <returns>Service collection for chaining.</returns>
|
|
public static IServiceCollection AddNotifyPostgresStorage(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
string sectionName = "Postgres:Notify")
|
|
{
|
|
services.Configure<PostgresOptions>(sectionName, configuration.GetSection(sectionName));
|
|
services.AddSingleton<NotifyDataSource>();
|
|
|
|
// Register repositories
|
|
services.AddScoped<IChannelRepository, ChannelRepository>();
|
|
services.AddScoped<IDeliveryRepository, DeliveryRepository>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds Notify PostgreSQL storage services with explicit options.
|
|
/// </summary>
|
|
/// <param name="services">Service collection.</param>
|
|
/// <param name="configureOptions">Options configuration action.</param>
|
|
/// <returns>Service collection for chaining.</returns>
|
|
public static IServiceCollection AddNotifyPostgresStorage(
|
|
this IServiceCollection services,
|
|
Action<PostgresOptions> configureOptions)
|
|
{
|
|
services.Configure(configureOptions);
|
|
services.AddSingleton<NotifyDataSource>();
|
|
|
|
// Register repositories
|
|
services.AddScoped<IChannelRepository, ChannelRepository>();
|
|
services.AddScoped<IDeliveryRepository, DeliveryRepository>();
|
|
|
|
return services;
|
|
}
|
|
}
|