Skip to content

geeksarray/how-to-use-automapper-in-aspnet-core-web-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How To Use AutoMapper in ASP.NET Core Web API

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.

What is AutoMapper

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.

  1. Install AutoMapper NuGet Package
  2. Generate Domain Model
  3. Create Data Transfer Objects (DTO)
  4. Setup AutoMapper configuration
  5. Inject AutoMapper Dependency
  6. Invoke Mapped object in API Controller
  7. Custom property Mapping using AutoMapper

For more detailed steps visit - https://geeksarray.com/blog/how-to-use-automapper-in-aspnet-core-web-api

ASP.NET Core AutoMapper Custom Mapping