refactor(EntityConfigurationOptions): aktualisiert, um IServiceCollection mit Callback zu konfigurieren
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.Core.Infrastructure.AutoMapper;
|
||||
|
||||
@@ -7,22 +6,21 @@ public static class DependencyInjection
|
||||
{
|
||||
public static EntityConfigurationOptions<TEntity> UseAutoMapper<TEntity>(this EntityConfigurationOptions<TEntity> options, params Type[] typeOfDtos)
|
||||
{
|
||||
IMapper? customRootMapper = null;
|
||||
|
||||
if (typeOfDtos.Length != 0)
|
||||
options.AddCustomMapper<EntityAutoMapper<TEntity>>(services =>
|
||||
{
|
||||
MapperConfigurationExpression AutoMapperConfiguration = new();
|
||||
|
||||
foreach (var typeOfDto in typeOfDtos)
|
||||
if (typeOfDtos.Length != 0)
|
||||
{
|
||||
AutoMapperConfiguration.CreateMap(typeof(TEntity), typeOfDto);
|
||||
AutoMapperConfiguration.CreateMap(typeOfDto, typeof(TEntity));
|
||||
services.AddAutoMapper(cnf =>
|
||||
{
|
||||
foreach (var typeOfDto in typeOfDtos)
|
||||
{
|
||||
cnf.CreateMap(typeof(TEntity), typeOfDto);
|
||||
cnf.CreateMap(typeOfDto, typeof(TEntity));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
customRootMapper = new MapperConfiguration(AutoMapperConfiguration).CreateMapper();
|
||||
}
|
||||
|
||||
options.AddCustomMapper(provider => new EntityAutoMapper<TEntity>(customRootMapper ?? provider.GetRequiredService<IMapper>()));
|
||||
});
|
||||
return options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user