using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System.Configuration; namespace DigitalData.Core.Application.Abstraction.DTO { /// /// Provides extension methods for dependency injection. /// public static class DIExtensions { /// /// Adds the to the service collection. /// /// The service collection to add the settings to. /// The updated service collection. /// /// Thrown if the 'CookieConsentSettings' section is missing or improperly configured in appsettings.json. /// public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services) { services.AddSingleton(sp => { var configuration = sp.GetRequiredService(); var settings = configuration.GetSection("CookieConsentSettings").Get(); return settings is null ? throw new ConfigurationErrorsException("The 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.") : settings; }); return services; } } }