using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using StellaOps.Infrastructure.Postgres;
using StellaOps.Infrastructure.Postgres.Options;
using StellaOps.Policy.Scoring.Receipts;
using StellaOps.Policy.Storage.Postgres.Repositories;
namespace StellaOps.Policy.Storage.Postgres;
///
/// Extension methods for configuring Policy PostgreSQL storage services.
///
public static class ServiceCollectionExtensions
{
///
/// Adds Policy PostgreSQL storage services.
///
/// Service collection.
/// Configuration root.
/// Configuration section name for PostgreSQL options.
/// Service collection for chaining.
public static IServiceCollection AddPolicyPostgresStorage(
this IServiceCollection services,
IConfiguration configuration,
string sectionName = "Postgres:Policy")
{
services.Configure(sectionName, configuration.GetSection(sectionName));
services.AddSingleton();
// Register repositories
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
return services;
}
///
/// Adds Policy PostgreSQL storage services with explicit options.
///
/// Service collection.
/// Options configuration action.
/// Service collection for chaining.
public static IServiceCollection AddPolicyPostgresStorage(
this IServiceCollection services,
Action configureOptions)
{
services.Configure(configureOptions);
services.AddSingleton();
// Register repositories
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddScoped();
return services;
}
}