// // Copyright (c) StellaOps. Licensed under the BUSL-1.1. // using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using StellaOps.Evidence.Pack.Resolvers; using StellaOps.Evidence.Pack.Storage; namespace StellaOps.Evidence.Pack; /// /// Extension methods for configuring Evidence Pack services. /// Sprint: SPRINT_20260109_011_005 Task: EVPK-005 /// public static class ServiceCollectionExtensions { /// /// Adds Evidence Pack services with default configuration. /// public static IServiceCollection AddEvidencePack(this IServiceCollection services) { return services.AddEvidencePack(_ => { }); } /// /// Adds Evidence Pack services with custom configuration. /// public static IServiceCollection AddEvidencePack( this IServiceCollection services, Action configure) { var options = new EvidencePackOptions(); configure(options); // Core services services.TryAddSingleton(TimeProvider.System); services.TryAddScoped(); services.TryAddScoped(); // Default to in-memory store if not configured services.TryAddSingleton(); // Add null type resolver if none configured services.TryAddEnumerable(ServiceDescriptor.Singleton()); return services; } /// /// Adds a custom type resolver for evidence resolution. /// public static IServiceCollection AddEvidenceTypeResolver( this IServiceCollection services) where TResolver : class, ITypeResolver { services.AddSingleton(); return services; } /// /// Adds a custom type resolver factory for evidence resolution. /// public static IServiceCollection AddEvidenceTypeResolver( this IServiceCollection services, Func factory) { services.AddSingleton(factory); return services; } /// /// Adds a passthrough type resolver for testing. /// public static IServiceCollection AddPassthroughResolver( this IServiceCollection services, params string[] types) { services.AddSingleton(sp => new PassthroughTypeResolver(types, sp.GetRequiredService())); return services; } /// /// Uses in-memory storage for Evidence Packs. /// public static IServiceCollection UseInMemoryEvidencePackStore( this IServiceCollection services) { services.RemoveAll(); services.AddSingleton(); return services; } } /// /// Configuration options for Evidence Pack services. /// public sealed class EvidencePackOptions { /// /// Gets or sets whether to auto-create packs from grounding results. /// public bool AutoCreateEnabled { get; set; } = true; /// /// Gets or sets the minimum grounding score for auto-creation. /// public double MinGroundingScore { get; set; } = 0.7; /// /// Gets or sets whether to auto-sign created packs. /// public bool AutoSign { get; set; } /// /// Gets or sets the signing key identifier. /// public string? SigningKeyId { get; set; } /// /// Gets or sets the retention period for unsigned packs in days. /// public int RetentionDays { get; set; } = 365; /// /// Gets or sets the retention period for signed packs in days. /// public int SignedRetentionDays { get; set; } = 2555; // 7 years }