Abp框架: Mapper not initialized. Call Initialize with appropriate configuration.

编写一个相关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);                

 

解决方法暂时还没找到,先记下

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-30
  • 2021-04-01
猜你喜欢
  • 2022-12-23
  • 2021-08-20
  • 2021-04-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
相关资源
相似解决方案