Files
jdescopingtool/NEW/src/JdeScoping.Infrastructure/DependencyInjection.cs
T
Joseph Doherty 604bfe919c refactor: address code review findings across all projects
Apply comprehensive fixes from code reviews including:
- Extract shared utilities (SqlFormatHelper, CellValueConverter, DbDestinationBase)
- Add interface abstractions (IAuthenticationService, IDatabaseMigrator, IMisQueryBuilder)
- Implement SecureStore for encrypted secrets storage
- Fix error handling with proper HTTP status codes and logging
- Optimize double enumeration in DevEtlRegistry
- Add DataSync.Dev README for developer onboarding
- Extract filter panel base classes to reduce duplication
- Update code review docs to mark all issues as fixed
2026-01-19 11:05:36 -05:00

61 lines
2.1 KiB
C#

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;
/// <summary>
/// Extension methods for registering infrastructure services.
/// </summary>
public static class InfrastructureDependencyInjection
{
/// <summary>
/// Adds infrastructure services (data sources, auth) to the service collection.
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configuration">The configuration.</param>
/// <returns>The service collection for chaining.</returns>
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
// Bind configuration
services.Configure<LdapOptions>(
configuration.GetSection(LdapOptions.SectionName));
// Register auth service based on configuration
var ldapOptions = configuration
.GetSection(LdapOptions.SectionName)
.Get<LdapOptions>();
if (ldapOptions?.UseFakeAuth == true)
{
services.AddScoped<IAuthenticationService, FakeAuthService>();
}
else
{
services.AddScoped<IAuthenticationService, LdapAuthService>();
}
// Register SecureStore for encrypted secrets storage
services.Configure<SecureStoreOptions>(
configuration.GetSection(SecureStoreOptions.SectionName));
services.AddSingleton<ISecureStoreService, SecureStoreService>();
// Register RSA key service backed by SecureStore
services.Configure<RsaKeyOptions>(
configuration.GetSection(RsaKeyOptions.SectionName));
services.AddSingleton<IRsaKeyService, SecureStoreRsaKeyService>();
// Register secrets migrator for one-time migration of existing secrets
services.AddSingleton<SecretsMigrator>();
return services;
}
}