Use AutoMapper in ASP.NET or ASP.NET Core

Ashish Patel
.NET Hub
Published in
2 min readJun 12, 2021

--

Getting started — How to use AutoMapper in .NET and .NET Core?

TL;DR

AutoMapper is a simple little library that helps to transform one object type to another. It is a convention-based object-to-object mapper that requires very little configuration.

AutoMapper is an object-object mapper. Object-object mapping works by transforming an input object of one type into an output object of a different type. What makes AutoMapper interesting is that it provides some interesting conventions to take the dirty work out of figuring out how to map type A to type B.

Most popular .NET Libraries every developer should know.

Configure AutoMapper in ASP.NET Core application

1. NuGet: To use AutoMapper, you need to install below NuGet packages.

PM> Install-Package AutoMapper
PM> Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection

2. Configuration: It should only happen once per AppDomain. That means the best place to put the configuration code is in application startup. ConfigureServices method is called by .NET Core at application startup time to register additional services.
You define the configuration using profiles. And then you let AutoMapper know in what…

--

--

Ashish Patel
.NET Hub

Cloud Architect • 4x AWS Certified • 6x Azure Certified • 1x Kubernetes Certified • MCP • .NET • Terraform • DevOps • Blogger [https://bit.ly/iamashishpatel]