Abp框架: Mapper not initialized. Call Initialize with appropriate configuration.
2017-03-24 15:18 小猫爱吃清蒸鱼 阅读(1431) 评论(0) 收藏 举报
编写一个相关AutoMapper映射后,出现图上错误。
检查过相关配置:
- 映射类所在项目类ApplicationModule.cs中有添加相关依赖[DependsOn(typeof(LMCoreModule), typeof(AbpAutoMapperModule))]
- 具体调用映射类配置,需要在“Initialize”方法中
public override void Initialize() { IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly()); // AutoMapper Configuration.Modules.AbpAutoMapper().Configurators.Add(mapper => { // 自定义配置映射 DtoMappings.Map(mapper); }); }
但是单独配置映射类,是没问题的:
// 正确配置 Mapper.Initialize(cfg => { cfg.CreateMap<ContentArticle, ArticleDto>() .ForMember(t => t.Data, opts => opts.MapFrom(d => d.Data)) .ForMember(t => t.ArticleId, opts => opts.MapFrom(d => d.Id)); }); var dto = Mapper.Map<ContentArticle, ArticleDto>(model);
解决方法暂时还没找到,先记下
浙公网安备 33010602011771号