.net core 中使用AutoMapper

什么是AutoMapper

  • AutoMapper是一个简单的库,旨在解决将一个对象映射到另一个对象

.Net Core中使用AutoMapper

  • 方式一 直接引入AutoMapper包

A good way to organize your mapping configurations is with profiles. Create classes that inherit from Profile and put the configuration in the constructor

官方文档上提到,配置映射关系的最好的方式就是创建一个类,让其继承自Profile,并将配置放入构造函数中

启动时,在Startup.cs配置文件中配置

在使用时,通过依赖注入的方式提供实例

  • 方式二,直接添加扩展AutoMapper的扩展库AutoMapper.Extensions.Microsoft.DependencyInjection,更加方便使用

posted @ 2020-08-15 13:23  一抹嫣红  阅读(1508)  评论(0编辑  收藏  举报