104 lines
3.8 KiB
C#
104 lines
3.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
using StellaOps.BinaryIndex.GoldenSet.Authoring;
|
|
using StellaOps.BinaryIndex.GoldenSet.Authoring.Extractors;
|
|
|
|
namespace StellaOps.BinaryIndex.GoldenSet;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering GoldenSet services.
|
|
/// </summary>
|
|
public static class GoldenSetServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Adds GoldenSet services to the dependency injection container.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configuration">The configuration.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddGoldenSetServices(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
|
|
// Configuration
|
|
services.AddOptions<GoldenSetOptions>()
|
|
.Bind(configuration.GetSection(GoldenSetOptions.SectionName))
|
|
.ValidateDataAnnotations()
|
|
.ValidateOnStart();
|
|
|
|
// Core services
|
|
services.TryAddSingleton<ISinkRegistry, SinkRegistry>();
|
|
services.TryAddSingleton<IGoldenSetValidator, GoldenSetValidator>();
|
|
|
|
// Cross-distro coverage matrix for backport validation
|
|
services.TryAddSingleton<ICrossDistroCoverageService, CrossDistroCoverageService>();
|
|
|
|
// Memory cache (if not already registered)
|
|
services.AddMemoryCache();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds GoldenSet authoring services to the dependency injection container.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddGoldenSetAuthoring(this IServiceCollection services)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
// Source extractors
|
|
services.TryAddEnumerable(ServiceDescriptor.Singleton<IGoldenSetSourceExtractor, NvdGoldenSetExtractor>());
|
|
|
|
// Composite extractor
|
|
services.TryAddSingleton<IGoldenSetExtractor, GoldenSetExtractor>();
|
|
|
|
// Upstream commit analyzer
|
|
services.TryAddSingleton<IUpstreamCommitAnalyzer, UpstreamCommitAnalyzer>();
|
|
|
|
// Enrichment service
|
|
services.TryAddScoped<IGoldenSetEnrichmentService, GoldenSetEnrichmentService>();
|
|
|
|
// Review workflow
|
|
services.TryAddScoped<IGoldenSetReviewService, GoldenSetReviewService>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds PostgreSQL-based GoldenSet storage to the dependency injection container.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddGoldenSetPostgresStorage(this IServiceCollection services)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
services.TryAddScoped<IGoldenSetStore, PostgresGoldenSetStore>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Adds a CVE validator implementation to the dependency injection container.
|
|
/// </summary>
|
|
/// <typeparam name="TValidator">The CVE validator implementation type.</typeparam>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddGoldenSetCveValidator<TValidator>(this IServiceCollection services)
|
|
where TValidator : class, ICveValidator
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
|
|
services.TryAddSingleton<ICveValidator, TValidator>();
|
|
|
|
return services;
|
|
}
|
|
}
|