// -----------------------------------------------------------------------------
// CertificateStatusServiceCollectionExtensions.cs
// Sprint: SPRINT_20260119_008 Certificate Status Provider
// Task: CSP-006 - DI Registration
// Description: DI registration for certificate status services.
// -----------------------------------------------------------------------------
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using StellaOps.Cryptography.CertificateStatus.Abstractions;
namespace StellaOps.Cryptography.CertificateStatus;
///
/// Extension methods for registering certificate status services.
///
public static class CertificateStatusServiceCollectionExtensions
{
///
/// Adds certificate status provider services to the service collection.
///
/// The service collection.
/// The service collection for chaining.
public static IServiceCollection AddCertificateStatusProvider(this IServiceCollection services)
{
// Ensure HttpClient factory and memory cache are available
services.AddHttpClient();
services.AddMemoryCache();
// Register components
services.TryAddSingleton();
services.TryAddSingleton();
services.TryAddSingleton();
return services;
}
///
/// Adds certificate status provider with custom HTTP client configuration.
///
/// The service collection.
/// Action to configure the OCSP HTTP client.
/// Action to configure the CRL HTTP client.
/// The service collection for chaining.
public static IServiceCollection AddCertificateStatusProvider(
this IServiceCollection services,
Action? configureOcspClient = null,
Action? configureCrlClient = null)
{
var ocspBuilder = services.AddHttpClient("OCSP", client =>
{
client.Timeout = TimeSpan.FromSeconds(10);
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/ocsp-response"));
});
configureOcspClient?.Invoke(ocspBuilder);
var crlBuilder = services.AddHttpClient("CRL", client =>
{
client.Timeout = TimeSpan.FromSeconds(30);
});
configureCrlClient?.Invoke(crlBuilder);
services.AddMemoryCache();
services.TryAddSingleton();
services.TryAddSingleton();
services.TryAddSingleton();
return services;
}
}