Implementierung von AddCookieConsentSettings zum Laden der Cookie-Zustimmungseinstellungen aus der Konfiguration
Eine Methode wurde hinzugefügt, um die CookieConsentSettings aus der appsettings.json als Singleton zu laden und zu registrieren. Diese Einstellungen verwalten die Benutzerzustimmung für Cookies. Beinhaltet Fehlerbehandlung für fehlende oder falsche Konfigurationen.
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Application.DTO;
|
||||
using DigitalData.Core.Contracts.Application;
|
||||
using DigitalData.Core.Contracts.Infrastructure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.Configuration;
|
||||
|
||||
namespace DigitalData.Core.Application
|
||||
{
|
||||
@@ -73,5 +76,20 @@ namespace DigitalData.Core.Application
|
||||
{
|
||||
return services.AddScoped<IJWTService<TClaimValue>, JWTService<TClaimValue>>(provider => new (tokenDescriptorFactory));
|
||||
}
|
||||
|
||||
public static IServiceCollection AddCookieConsentSettings(this IServiceCollection services)
|
||||
{
|
||||
services.AddSingleton<CookieConsentSettings>(sp =>
|
||||
{
|
||||
var configuration = sp.GetRequiredService<IConfiguration>();
|
||||
var settings = configuration.GetSection("CookieConsentSettings").Get<CookieConsentSettings>();
|
||||
if (settings is null)
|
||||
{
|
||||
throw new ConfigurationErrorsException("The 'CookieConsentSettings' section is missing or improperly configured in appsettings.json.");
|
||||
}
|
||||
return settings;
|
||||
});
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user