using JdeScoping.Core.Interfaces;
using JdeScoping.Core.Options;
using JdeScoping.Infrastructure.Auth;
using JdeScoping.Infrastructure.Options;
using JdeScoping.Infrastructure.Security;
using Microsoft.Extensions.Configuration;
namespace Microsoft.Extensions.DependencyInjection;
///
/// Extension methods for registering infrastructure services.
///
public static class InfrastructureDependencyInjection
{
///
/// Adds infrastructure services (data sources, auth) to the service collection.
///
/// The service collection.
/// The configuration.
/// The service collection for chaining.
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
// Bind configuration
services.Configure(
configuration.GetSection(LdapOptions.SectionName));
// Register auth service based on configuration
var ldapOptions = configuration
.GetSection(LdapOptions.SectionName)
.Get();
if (ldapOptions?.UseFakeAuth == true)
{
services.AddScoped();
}
else
{
services.AddScoped();
}
// Register SecureStore for encrypted secrets storage
services.Configure(
configuration.GetSection(SecureStoreOptions.SectionName));
services.AddSingleton();
// Register RSA key service backed by SecureStore
services.Configure(
configuration.GetSection(RsaKeyOptions.SectionName));
services.AddSingleton();
// Register secrets migrator for one-time migration of existing secrets
services.AddSingleton();
return services;
}
}