我正在使用AutoMapper 9,我想映射我的嵌套表。在较旧版本的AutoMapper中,我使用了这样的“ CreateMap”:
CreateMap<Table, ViewModel>().AfterMap((s, d) => Mapper.Map(s.Table2, d)).ReverseMap();
我在下面找到了这个示例,但是它仅适用于表的一个元素。
CreateMap<Table, ViewModel>().ForMember(d=>d.Items,o=>o.MapFrom(s=>s.Table2.Items));
但是在新版本(Mapper.Map)中无法正常工作,因为AutoMapper使用依赖项注入。如何以简单的方式在新版本中使用嵌套映射?我并没有隐瞒我想在没有依赖项注入的情况下使用AutoMapper。