// ----------------------------------------------------------------------------- // ServiceCollectionExtensions.cs // Sprint: SPRINT_20260118_017_Evidence_artifact_store_unification // Tasks: AS-002, AS-003 - Service registration // Description: DI registration for artifact store services // ----------------------------------------------------------------------------- using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using StellaOps.Artifact.Core; using StellaOps.Concelier.SbomIntegration.Parsing; using StellaOps.Determinism; using StellaOps.Infrastructure.Postgres.Options; namespace StellaOps.Artifact.Infrastructure; /// /// Extension methods for registering artifact store services. /// public static class ServiceCollectionExtensions { /// /// Adds unified artifact store services with S3 backend. /// /// Service collection. /// Configuration root. /// Configuration section for options. /// Service collection for chaining. public static IServiceCollection AddUnifiedArtifactStore( this IServiceCollection services, IConfiguration configuration, string sectionName = "ArtifactStore") { ArgumentNullException.ThrowIfNull(configuration); // Configure S3 store options services.Configure(configuration.GetSection($"{sectionName}:S3")); // Configure PostgreSQL options for index services.Configure(ArtifactDataSource.OptionsName, configuration.GetSection($"{sectionName}:Postgres")); services.TryAddSingleton(TimeProvider.System); services.TryAddSingleton(); services.TryAddScoped(); // Register data source services.AddSingleton(); // Register core services services.AddSingleton(); services.AddSingleton(); // Register index repository services.AddScoped(); // Register S3 artifact store services.AddScoped(); return services; } /// /// Adds unified artifact store with in-memory backend (for testing). /// /// Service collection. /// Service collection for chaining. public static IServiceCollection AddInMemoryArtifactStore(this IServiceCollection services) { services.TryAddSingleton(TimeProvider.System); services.TryAddSingleton(); services.TryAddScoped(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); return services; } /// /// Adds artifact migration services. /// /// Service collection. /// Options configuration. /// Service collection for chaining. public static IServiceCollection AddArtifactMigration( this IServiceCollection services, Action? configure = null) { var options = new ArtifactMigrationOptions(); configure?.Invoke(options); services.AddSingleton(options); services.TryAddSingleton(TimeProvider.System); services.TryAddSingleton(); services.AddScoped(); return services; } }