Files
git.stella-ops.org/src/__Libraries/StellaOps.Artifact.Infrastructure/ServiceCollectionExtensions.cs

98 lines
4.1 KiB
C#

// -----------------------------------------------------------------------------
// 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;
/// <summary>
/// Extension methods for registering artifact store services.
/// </summary>
public static class ServiceCollectionExtensions
{
/// <summary>
/// Adds unified artifact store services with S3 backend.
/// </summary>
/// <param name="services">Service collection.</param>
/// <param name="configuration">Configuration root.</param>
/// <param name="sectionName">Configuration section for options.</param>
/// <returns>Service collection for chaining.</returns>
public static IServiceCollection AddUnifiedArtifactStore(
this IServiceCollection services,
IConfiguration configuration,
string sectionName = "ArtifactStore")
{
ArgumentNullException.ThrowIfNull(configuration);
// Configure S3 store options
services.Configure<S3UnifiedArtifactStoreOptions>(configuration.GetSection($"{sectionName}:S3"));
// Configure PostgreSQL options for index
services.Configure<PostgresOptions>(ArtifactDataSource.OptionsName, configuration.GetSection($"{sectionName}:Postgres"));
services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton<IGuidProvider, SystemGuidProvider>();
services.TryAddScoped<IArtifactTenantContext, ArtifactTenantContext>();
// Register data source
services.AddSingleton<ArtifactDataSource>();
// Register core services
services.AddSingleton<IParsedSbomParser, ParsedSbomParser>();
services.AddSingleton<ICycloneDxExtractor, CycloneDxExtractor>();
// Register index repository
services.AddScoped<IArtifactIndexRepository, PostgresArtifactIndexRepository>();
// Register S3 artifact store
services.AddScoped<IArtifactStore, S3UnifiedArtifactStore>();
return services;
}
/// <summary>
/// Adds unified artifact store with in-memory backend (for testing).
/// </summary>
/// <param name="services">Service collection.</param>
/// <returns>Service collection for chaining.</returns>
public static IServiceCollection AddInMemoryArtifactStore(this IServiceCollection services)
{
services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton<IGuidProvider, SystemGuidProvider>();
services.TryAddScoped<IArtifactTenantContext, ArtifactTenantContext>();
services.AddSingleton<IParsedSbomParser, ParsedSbomParser>();
services.AddSingleton<ICycloneDxExtractor, CycloneDxExtractor>();
services.AddSingleton<IArtifactIndexRepository, InMemoryArtifactIndexRepository>();
services.AddSingleton<IArtifactStore, InMemoryArtifactStore>();
return services;
}
/// <summary>
/// Adds artifact migration services.
/// </summary>
/// <param name="services">Service collection.</param>
/// <param name="configure">Options configuration.</param>
/// <returns>Service collection for chaining.</returns>
public static IServiceCollection AddArtifactMigration(
this IServiceCollection services,
Action<ArtifactMigrationOptions>? configure = null)
{
var options = new ArtifactMigrationOptions();
configure?.Invoke(options);
services.AddSingleton(options);
services.TryAddSingleton(TimeProvider.System);
services.TryAddSingleton<IGuidProvider, SystemGuidProvider>();
services.AddScoped<ArtifactMigrationService>();
return services;
}
}