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.
This commit is contained in:
2026-08-13 09:37:14 +02:00
parent 00ae8e1ba0
commit 893addb45d
2 changed files with 22 additions and 0 deletions

View File

@@ -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;
}
}

View File

@@ -0,0 +1,19 @@
using AutoMapper;
using DigitalData.MessagingService.Domain.Entities;
namespace DigitalData.MessagingService.Infrastructure.Mappings;
/// <summary>
/// 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.
/// </summary>
public class EntitySelfMappingProfile : Profile
{
public EntitySelfMappingProfile()
{
CreateMap<EmailAccount, EmailAccount>();
CreateMap<ReceivedEmail, ReceivedEmail>();
CreateMap<EmailAttachment, EmailAttachment>();
}
}