27 lines
822 B
C#

using Microsoft.Extensions.DependencyInjection;
namespace DigitalData.Core.Infrastructure.AutoMapper;
public static class DependencyInjection
{
public static EntityConfigurationOptions<TEntity> UseAutoMapper<TEntity>(this EntityConfigurationOptions<TEntity> options, params Type[] typeOfDtos)
{
options.AddCustomMapper<EntityAutoMapper<TEntity>>(services =>
{
if (typeOfDtos.Length != 0)
{
services.AddAutoMapper(cnf =>
{
foreach (var typeOfDto in typeOfDtos)
{
cnf.CreateMap(typeof(TEntity), typeOfDto);
cnf.CreateMap(typeOfDto, typeof(TEntity));
}
});
}
});
return options;
}
}