Automapper says Mapper.Map is obsolete, global mappings?

后端 未结 5 1218
孤街浪徒
孤街浪徒 2020-12-12 21:01

I had defined in my project a global Automapper configuration that would allow me to use Mapper.Map(sourceObject); in my code. (See my configu

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-12 21:46

    You can find configured AutoMapper 4.2 in my ASP.NET MVC Template project here: https://github.com/NikolayIT/ASP.NET-MVC-Template

    1. Create these classes: https://github.com/NikolayIT/ASP.NET-MVC-Template/tree/master/ASP.NET%20MVC%205/Web/MvcTemplate.Web.Infrastructure/Mapping

    2. Annotate view models with IMapFrom<>: https://github.com/NikolayIT/ASP.NET-MVC-Template/blob/master/ASP.NET%20Core/Web/AspNetCoreTemplate.Web/ViewModels/Settings/SettingViewModel.cs

    3. Use it as .To(). Example: https://github.com/NikolayIT/ASP.NET-MVC-Template/blob/master/ASP.NET%20MVC%205/Web/MvcTemplate.Web/Controllers/HomeController.cs#L27

提交回复
热议问题