From 893addb45df1e99c21b9b57faf6985562037b90b Mon Sep 17 00:00:00 2001 From: TekH Date: Thu, 13 Aug 2026 09:37:14 +0200 Subject: [PATCH] Add AutoMapper profile for entity self-mappings Introduce `EntitySelfMappingProfile` to enable self-mappings (T -> T) for domain entities (`EmailAccount`, `ReceivedEmail`, `EmailAttachment`). This ensures uniform AutoMapper usage in the generic repository, regardless of whether the target type is a DTO or the entity itself. Added necessary `using` directives for `AutoMapper` and domain entities. --- .../DependencyInjection.cs | 3 +++ .../Mappings/EntitySelfMappingProfile.cs | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/infrastructure/DigitalData.MessagingService.Infrastructure/Mappings/EntitySelfMappingProfile.cs diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/DependencyInjection.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/DependencyInjection.cs index 0060fa5..297b5ec 100644 --- a/src/infrastructure/DigitalData.MessagingService.Infrastructure/DependencyInjection.cs +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/DependencyInjection.cs @@ -64,6 +64,9 @@ public static class DependencyInjection services.AddScoped(typeof(IRepository<>), typeof(Repository<>)); + // AutoMapper - Register entity self-mappings (T -> T) for generic repository + services.AddAutoMapper(config => config.AddMaps(typeof(EntitySelfMappingProfile).Assembly)); + return services; } } diff --git a/src/infrastructure/DigitalData.MessagingService.Infrastructure/Mappings/EntitySelfMappingProfile.cs b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Mappings/EntitySelfMappingProfile.cs new file mode 100644 index 0000000..05ff608 --- /dev/null +++ b/src/infrastructure/DigitalData.MessagingService.Infrastructure/Mappings/EntitySelfMappingProfile.cs @@ -0,0 +1,19 @@ +using AutoMapper; +using DigitalData.MessagingService.Domain.Entities; + +namespace DigitalData.MessagingService.Infrastructure.Mappings; + +/// +/// AutoMapper profile that registers self-mappings (T -> T) for all domain entities. +/// This allows AutoMapper to be used uniformly in the generic repository +/// regardless of whether TDto is a DTO or the entity type itself. +/// +public class EntitySelfMappingProfile : Profile +{ + public EntitySelfMappingProfile() + { + CreateMap(); + CreateMap(); + CreateMap(); + } +}