We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
automapper的如果有MapFromAttribute和实现IAutoMapperConfiguration,后者会配置会失效 #109
由于IAutoMapperConfiguration的优先级比Profile的方式低,无法提升IAutoMapperConfiguration的优先级 统一改为使用Profile的方式来管理对象映射配置 更改如下:
IAutoMapperConfiguration
Profile
IMapTuple
Order
AutoMapperTupleBase
MapTupleProfile
MapFromAndMapToProfile
old: public class AutoMapperConfiguration : IAutoMapperConfiguration { /// <summary> /// 创建对象映射 /// </summary> /// <param name="mapper">映射配置表达</param> public void CreateMaps(MapperConfigurationExpression mapper) { mapper.CreateMap<Role, RoleNode>().ForMember(rn => rn.RoleId, opt => opt.MapFrom(r => r.Id)) .ForMember(rn => rn.RoleName, opt => opt.MapFrom(r => r.Name)); } } new: public class AutoMapperConfiguration : AutoMapperTupleBase { /// <summary> /// 创建对象映射 /// </summary> public override void CreateMap() { CreateMap<Role, RoleNode>().ForMember(rn => rn.RoleId, opt => opt.MapFrom(r => r.Id)) .ForMember(rn => rn.RoleName, opt => opt.MapFrom(r => r.Name)); } }
The text was updated successfully, but these errors were encountered:
fix(automapper): 重构AutoMapper模块,解决复杂映射配置优先级低的问题 #230 #109
fabcb64
配合 #230 的更改,更新业务代码
2a9dde3
No branches or pull requests
您的功能请求与现有问题有关吗?请描述
automapper的如果有MapFromAttribute和实现IAutoMapperConfiguration,后者会配置会失效 #109
描述您想要的需求方案
由于
IAutoMapperConfiguration
的优先级比Profile
的方式低,无法提升IAutoMapperConfiguration
的优先级统一改为使用
Profile
的方式来管理对象映射配置更改如下:
IAutoMapperConfiguration
IMapTuple
增加Order
属性,用于配置多个Profile的执行顺序IMapTuple
的实现基类AutoMapperTupleBase
,其他模块的对象映射均以实现此基类为准MapTupleProfile
更名为MapFromAndMapToProfile
,Order默认为-9999,优先执行[MapFrom], [MapTo]的映射IAutoMapperConfiguration
的实现类改为实现基类AutoMapperTupleBase
,Order默认为0,其配置可以覆盖[MapFrom], [MapTo]中的配置一个
AutoMapperTupleBase
实现类的示例The text was updated successfully, but these errors were encountered: