Developer 02 6e973a494e feat: Implementieren der Verschlüsselungs- und Entschlüsselungsdienste mit AES und Integration in die API
- Hinzufügen der `Encryptor`-Klasse für AES-Verschlüsselung und -Entschlüsselung.
- Implementierung des `EncryptionController` zur Bereitstellung von Endpunkten für Verschlüsselung, Entschlüsselung und Generierung von Verschlüsselungsparametern.
- Erweiterung der DI-Konfiguration mit `AddEncryptor`-Erweiterungsmethode und Integration in `Program.cs`.
- Bedingte Registrierung des `EncryptionController` basierend auf der Konfiguration `UseEncryptor`, um sicherzustellen, dass der Controller nur bei Bedarf verfügbar ist.
- Implementierung von Lazy Loading für die Verbindungszeichenfolge in `UserManagerDbContext` zur sicheren Handhabung von verschlüsselten Verbindungszeichenfolgen.
2024-08-29 11:35:47 +02:00

54 lines
2.7 KiB
C#

using DigitalData.UserManager.Application.Contracts;
using DigitalData.UserManager.Application.MappingProfiles;
using DigitalData.UserManager.Application.Services;
using DigitalData.UserManager.Application.Services.Options;
using DigitalData.UserManager.Infrastructure.Contracts;
using DigitalData.UserManager.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.UserManager.Application
{
public static class DIExtensions
{
/// <summary>
/// Adds the UserManager services and repositories to the specified <see cref="IServiceCollection"/>.
/// This method registers the necessary mappings, repositories, and services for the UserManager.
/// </summary>
/// <typeparam name="TDbContext">The type of the DbContext to use for the repositories.</typeparam>
/// <param name="services">The IServiceCollection to which the services will be added.</param>
/// <returns>The updated IServiceCollection.</returns>
public static IServiceCollection AddUserManager<TDbContext>(this IServiceCollection services)
where TDbContext : DbContext
=> services
.AddAutoMapper(typeof(UserMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupMappingProfile).Assembly)
.AddAutoMapper(typeof(GroupOfUserMappingProfile).Assembly)
.AddAutoMapper(typeof(ModuleMappingProfile).Assembly)
.AddAutoMapper(typeof(ModuleOfUserMappingProfile).Assembly)
.AddAutoMapper(typeof(UserRepMappingProfile).Assembly)
.AddScoped<IUserRepository, UserRepository<TDbContext>>()
.AddScoped<IGroupRepository, GroupRepository<TDbContext>>()
.AddScoped<IGroupOfUserRepository, GroupOfUserRepository<TDbContext>>()
.AddScoped<IModuleRepository, ModuleRepository<TDbContext>>()
.AddScoped<IModuleOfUserRepository, ModuleOfUserRepository<TDbContext>>()
.AddScoped<IUserRepRepository, UserRepRepository<TDbContext>>()
.AddScoped<IUserService, UserService>()
.AddScoped<IGroupService, GroupService>()
.AddScoped<IGroupOfUserService, GroupOfUserService>()
.AddScoped<IModuleService, ModuleService>()
.AddScoped<IModuleOfUserService, ModuleOfUserService>()
.AddScoped<IUserRepService, UserRepService>();
public static IServiceCollection AddEncryptor(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<Encryptor>();
services.Configure<EncryptionParameters>(configuration);
return services;
}
}
}