什么是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,更加方便使用