71 lines
3.1 KiB
C#
71 lines
3.1 KiB
C#
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;
|
|
|
|
/// <summary>
|
|
/// Extension methods for configuring Policy PostgreSQL storage services.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds Policy 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 AddPolicyPostgresStorage(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
string sectionName = "Postgres:Policy")
|
|
{
|
|
services.Configure<PostgresOptions>(sectionName, configuration.GetSection(sectionName));
|
|
services.AddSingleton<PolicyDataSource>();
|
|
|
|
// Register repositories
|
|
services.AddScoped<IPackRepository, PackRepository>();
|
|
services.AddScoped<IPackVersionRepository, PackVersionRepository>();
|
|
services.AddScoped<IRuleRepository, RuleRepository>();
|
|
services.AddScoped<IRiskProfileRepository, RiskProfileRepository>();
|
|
services.AddScoped<IEvaluationRunRepository, EvaluationRunRepository>();
|
|
services.AddScoped<IExceptionRepository, ExceptionRepository>();
|
|
services.AddScoped<IReceiptRepository, PostgresReceiptRepository>();
|
|
services.AddScoped<IExplanationRepository, ExplanationRepository>();
|
|
services.AddScoped<IPolicyAuditRepository, PolicyAuditRepository>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds Policy 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 AddPolicyPostgresStorage(
|
|
this IServiceCollection services,
|
|
Action<PostgresOptions> configureOptions)
|
|
{
|
|
services.Configure(configureOptions);
|
|
services.AddSingleton<PolicyDataSource>();
|
|
|
|
// Register repositories
|
|
services.AddScoped<IPackRepository, PackRepository>();
|
|
services.AddScoped<IPackVersionRepository, PackVersionRepository>();
|
|
services.AddScoped<IRuleRepository, RuleRepository>();
|
|
services.AddScoped<IRiskProfileRepository, RiskProfileRepository>();
|
|
services.AddScoped<IEvaluationRunRepository, EvaluationRunRepository>();
|
|
services.AddScoped<IExceptionRepository, ExceptionRepository>();
|
|
services.AddScoped<IReceiptRepository, PostgresReceiptRepository>();
|
|
services.AddScoped<IExplanationRepository, ExplanationRepository>();
|
|
services.AddScoped<IPolicyAuditRepository, PolicyAuditRepository>();
|
|
|
|
return services;
|
|
}
|
|
}
|