如何在c#中的automapper配置文件中注入服务

时间:2017-06-02 08:56:40

标签: c# model-view-controller mapping automapper

我正在使用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());                    

            });
    }

0 个答案:

没有答案