File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -200,4 +200,42 @@ public class OrderSubmittedEventConsumer : IConsumer<OrderSubmitted>
200200 }
201201 }
202202```
203+ ## AA.AutoMapper用法
204+ ##### 实现IMapperConfiguration接口,创建映射规则配置
203205
206+ ```
207+ public class WebMapperConfigurations : IMapperConfiguration
208+ {
209+ public int Order { get { return 0; } }
210+
211+ public Action<IMapperConfigurationExpression> GetConfiguration()
212+ {
213+ Action<IMapperConfigurationExpression> action = cfg =>
214+ {
215+ cfg.CreateMap<UserVm, UserInput>();
216+ };
217+ return action;
218+ }
219+ }
220+ ```
221+ ##### 在程序startup调用配置
222+
223+ ```
224+ var mapperConfig = new WebMapperConfigurations();
225+ AutoMapperConfiguration.Init(new List<Action<IMapperConfigurationExpression>> { mapperConfig.GetConfiguration() });
226+ ObjectMapping.ObjectMapManager.ObjectMapper = new AutoMapperObjectMapper();
227+ ```
228+ ##### 利用扩展方法MapTo执行映射
229+
230+ ```
231+ [Fact]
232+ public void TestMap()
233+ {
234+ //init
235+ Init();
236+ UserVm userVm = new UserVm { Id = 1, Name = "成天" ,Remark="微信公众号:dotNet知音"};
237+ var userDto = userVm.MapTo<UserInput>();
238+ //var userDto2 = userVm.MapTo<UserVm,UserInput>();
239+
240+ }
241+ ```
You can’t perform that action at this time.
0 commit comments