This blog explains how to use AutoMapper in ASP.NET Core Web API project, the configuration of AutoMapper, mapping domain and DTOs, and custom property mapping.
AutoMapper is an object-to-object mapper which helps you to avoid manual mapping of each required property while transferring data from one object to another. Manual mapping is tedious and time-consuming whereas Automapper does mapping in a very clean and readable way. In an MVC application you mostly map model objects to View Models similarly in Web API you map domain objects to DTOs.
- Install AutoMapper NuGet Package
- Generate Domain Model
- Create Data Transfer Objects (DTO)
- Setup AutoMapper configuration
- Inject AutoMapper Dependency
- Invoke Mapped object in API Controller
- Custom property Mapping using AutoMapper
For more detailed steps visit - https://geeksarray.com/blog/how-to-use-automapper-in-aspnet-core-web-api