.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,更加方便使用


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM