87 lines
4.0 KiB
C#
87 lines
4.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using StellaOps.Infrastructure.Postgres.Migrations;
|
|
using StellaOps.Infrastructure.Postgres.Options;
|
|
using StellaOps.Signals.Persistence;
|
|
using StellaOps.Signals.Services;
|
|
using StellaOps.Signals.Persistence.Postgres.Repositories;
|
|
|
|
namespace StellaOps.Signals.Persistence.Postgres;
|
|
|
|
/// <summary>
|
|
/// Extension methods for configuring Signals PostgreSQL storage services.
|
|
/// </summary>
|
|
public static class ServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds Signals 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 AddSignalsPostgresStorage(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration,
|
|
string sectionName = "Postgres:Signals")
|
|
{
|
|
services.Configure<PostgresOptions>(configuration.GetSection(sectionName));
|
|
services.TryAddSingleton(TimeProvider.System);
|
|
services.AddSingleton<SignalsDataSource>();
|
|
|
|
services.AddStartupMigrations(
|
|
SignalsDataSource.DefaultSchemaName,
|
|
"Signals.Storage",
|
|
typeof(SignalsDataSource).Assembly);
|
|
|
|
// Register repositories
|
|
services.AddSingleton<ICallgraphRepository, PostgresCallgraphRepository>();
|
|
services.AddSingleton<IReachabilityFactRepository, PostgresReachabilityFactRepository>();
|
|
services.AddSingleton<IUnknownsRepository, PostgresUnknownsRepository>();
|
|
services.AddSingleton<IReachabilityStoreRepository, PostgresReachabilityStoreRepository>();
|
|
services.AddSingleton<IDeploymentRefsRepository, PostgresDeploymentRefsRepository>();
|
|
services.AddSingleton<IGraphMetricsRepository, PostgresGraphMetricsRepository>();
|
|
services.AddSingleton<ICallGraphQueryRepository, PostgresCallGraphQueryRepository>();
|
|
services.AddSingleton<ICallGraphProjectionRepository, PostgresCallGraphProjectionRepository>();
|
|
|
|
services.AddSingleton<ICallGraphSyncService, CallGraphSyncService>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds Signals 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 AddSignalsPostgresStorage(
|
|
this IServiceCollection services,
|
|
Action<PostgresOptions> configureOptions)
|
|
{
|
|
services.Configure(configureOptions);
|
|
services.TryAddSingleton(TimeProvider.System);
|
|
services.AddSingleton<SignalsDataSource>();
|
|
|
|
services.AddStartupMigrations(
|
|
SignalsDataSource.DefaultSchemaName,
|
|
"Signals.Storage",
|
|
typeof(SignalsDataSource).Assembly);
|
|
|
|
// Register repositories
|
|
services.AddSingleton<ICallgraphRepository, PostgresCallgraphRepository>();
|
|
services.AddSingleton<IReachabilityFactRepository, PostgresReachabilityFactRepository>();
|
|
services.AddSingleton<IUnknownsRepository, PostgresUnknownsRepository>();
|
|
services.AddSingleton<IReachabilityStoreRepository, PostgresReachabilityStoreRepository>();
|
|
services.AddSingleton<IDeploymentRefsRepository, PostgresDeploymentRefsRepository>();
|
|
services.AddSingleton<IGraphMetricsRepository, PostgresGraphMetricsRepository>();
|
|
services.AddSingleton<ICallGraphQueryRepository, PostgresCallGraphQueryRepository>();
|
|
services.AddSingleton<ICallGraphProjectionRepository, PostgresCallGraphProjectionRepository>();
|
|
|
|
services.AddSingleton<ICallGraphSyncService, CallGraphSyncService>();
|
|
|
|
return services;
|
|
}
|
|
}
|