68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
// VexTrustGateServiceCollectionExtensions - DI registration
|
|
// Part of SPRINT_1227_0004_0003: VexTrustGate Policy Integration
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
using StellaOps.Policy.Engine.Confidence;
|
|
using StellaOps.Policy.Engine.Gates;
|
|
|
|
namespace StellaOps.Policy.Engine.DependencyInjection;
|
|
|
|
/// <summary>
|
|
/// Extension methods for registering VEX trust gate services.
|
|
/// </summary>
|
|
public static class VexTrustGateServiceCollectionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Add VEX trust gate services to the DI container.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configuration">The configuration root.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddVexTrustGate(
|
|
this IServiceCollection services,
|
|
IConfiguration configuration)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configuration);
|
|
|
|
// Bind options
|
|
services.Configure<VexTrustGateOptions>(
|
|
configuration.GetSection(VexTrustGateOptions.SectionKey));
|
|
|
|
// Register gate
|
|
services.TryAddSingleton<IVexTrustGate, VexTrustGate>();
|
|
|
|
// Register metrics
|
|
services.TryAddSingleton<VexTrustGateMetrics>();
|
|
|
|
// Register confidence factor provider
|
|
services.TryAddSingleton<IConfidenceFactorProvider, VexTrustConfidenceFactorProvider>();
|
|
|
|
return services;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Add VEX trust gate with custom options.
|
|
/// </summary>
|
|
/// <param name="services">The service collection.</param>
|
|
/// <param name="configureOptions">Action to configure options.</param>
|
|
/// <returns>The service collection for chaining.</returns>
|
|
public static IServiceCollection AddVexTrustGate(
|
|
this IServiceCollection services,
|
|
Action<VexTrustGateOptions> configureOptions)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(services);
|
|
ArgumentNullException.ThrowIfNull(configureOptions);
|
|
|
|
services.Configure(configureOptions);
|
|
|
|
services.TryAddSingleton<IVexTrustGate, VexTrustGate>();
|
|
services.TryAddSingleton<VexTrustGateMetrics>();
|
|
services.TryAddSingleton<IConfidenceFactorProvider, VexTrustConfidenceFactorProvider>();
|
|
|
|
return services;
|
|
}
|
|
}
|