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(); + } +}