AutoMapper is a simple little library built to solve a deceptively complex problem - getting rid of code that mapped one object to another. This type of code is rather dreary and boring to write, so why not invent a tool to do it for us?
1) Install the neccessary NuGet packages
- PM> Install-Package AutoMapper
- PM> Install-Package AutoMapper.Extensions.Microsoft.DependencyInjection
2) AutoMapper service
As the next step we need to call the AutoMapper from the
3) Register mapping profiles
Create a new class for our mapping profile (on your favorite location) and let this class inherit from Profile.
It is important to know, that the mapping is a one way mapping, if you also need the mapping in the other direction you have to define both mappings.
4) Invoke the mapper
The AutoMapper.Extensions.Microsoft.DependencyInjection package provides AutoMapper through Dependency Injection.
AutoMapper give use a really simple way to map between objects, if you need further informations use the official GitHub Project (very well documented). https://github.com/AutoMapper/AutoMapper/wiki/Getting-started.
Subscribe to Sascha Heyer, B.Sc., Software and Machine Learning Engineer
Get the latest posts delivered right to your inbox