.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