我正在使用AutoMapper配置文件来映射实体。在其中一个映射配置文件中,我需要调用服务方法。我试图使用配置文件构造函数注入服务,但后来我无法注册/添加它。任何想法我该如何处理?
public class HistoryProfile : Profile
{
private readonly MappingService _mappingService;
public HistoryProfile(MappingService mappingService)
{
_mappingService = mappingService;
this.CreateMap<HistoryCHR, History>()
.ForMember(h => h.BirthDate, hisChr => hisChr.MapFrom(x => x.DateOfBirth))
.....................
}
}
private static void InitializeSpecificProfiles()
{
Mapper.Initialize(
cfg =>
{
cfg.AddProfile(new HistoryProfile());
});
}