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; /// /// Extension methods for configuring Signals PostgreSQL storage services. /// public static class ServiceCollectionExtensions { /// /// Adds Signals PostgreSQL storage services. /// /// Service collection. /// Configuration root. /// Configuration section name for PostgreSQL options. /// Service collection for chaining. public static IServiceCollection AddSignalsPostgresStorage( this IServiceCollection services, IConfiguration configuration, string sectionName = "Postgres:Signals") { services.Configure(configuration.GetSection(sectionName)); services.TryAddSingleton(TimeProvider.System); services.AddSingleton(); services.AddStartupMigrations( SignalsDataSource.DefaultSchemaName, "Signals.Storage", typeof(SignalsDataSource).Assembly); // Register repositories services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } /// /// Adds Signals PostgreSQL storage services with explicit options. /// /// Service collection. /// Options configuration action. /// Service collection for chaining. public static IServiceCollection AddSignalsPostgresStorage( this IServiceCollection services, Action configureOptions) { services.Configure(configureOptions); services.TryAddSingleton(TimeProvider.System); services.AddSingleton(); services.AddStartupMigrations( SignalsDataSource.DefaultSchemaName, "Signals.Storage", typeof(SignalsDataSource).Assembly); // Register repositories services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } }