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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user