using System; using System.Collections.Generic; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using StellaOps.Cryptography; using StellaOps.Cryptography.PluginLoader; namespace StellaOps.Cryptography.DependencyInjection; /// /// DI extension methods for configuration-driven crypto plugin loading. /// public static partial class CryptoPluginServiceCollectionExtensions { /// /// Registers crypto providers using configuration-driven plugin loading. /// Replaces hardcoded provider registrations with dynamic plugin loader. /// /// Service collection. /// Application configuration. /// Optional plugin configuration action. /// The service collection. public static IServiceCollection AddStellaOpsCryptoWithPlugins( this IServiceCollection services, IConfiguration configuration, Action? configurePlugins = null) { ArgumentNullException.ThrowIfNull(services); ArgumentNullException.ThrowIfNull(configuration); CryptoComplianceOptionsRegistration.Register(services, bindFromConfiguration: false); services.Configure(options => { configuration.GetSection(CryptoComplianceOptions.SectionKey).Bind(options); }); services.Configure(options => { configuration.GetSection("StellaOps:Crypto:Plugins").Bind(options); configurePlugins?.Invoke(options); }); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton(); services.TryAddSingleton, CryptoPluginProviderList>(); services.TryAddSingleton, CryptoPluginProviderEnumerable>(); services.TryAddSingleton(); return services; } }