๐ก ๐๐ฎ๐ญ๐จ๐ฆ๐๐ฉ๐ฉ๐๐ซ ๐ข๐ง .๐๐๐
๐ก ๐๐ฎ๐ญ๐จ๐ฆ๐๐ฉ๐ฉ๐๐ซ ๐ข๐งย .๐๐๐
In ourย .NET application, we frequently need to map data between different object models. Sometimes while retrieving data from database, we need to convert database object to our DTOs and vice versa, we can do this by manually selecting properties each time and mapping them with DTO properties. This process is time consuming if we have to map same data at multiple places within our application. Here Automapper comes in play.
๐๐๐ง๐๐๐ข๐ญ๐ฌ ๐จ๐ ๐๐ฎ๐ญ๐จ๐ฆ๐๐ฉ๐ฉ๐๐ซ
1. It reduces the repetition of code and saves time.
2. Code becomes clean and easy to manage.
๐๐จ๐ง๐ฌ ๐จ๐ ๐๐ฎ๐ญ๐จ๐ฆ๐๐ฉ๐ฉ๐๐ซ
1. If not managed properly it can create issues at runtime
2. For large number of mappings, it can lead to high resource consumption and become slow.
3. Not suitable for complex objects when multiple entities are linked in itย
๐๐จ๐ฐ ๐ญ๐จ ๐ฎ๐ฌ๐ ๐๐ฎ๐ญ๐จ๐ฆ๐๐ฉ๐ฉ๐๐ซ
1. Install NuGet Packages
2. Add Dependency Injection of Automapper
3. Create your Mapper and Inherit it from Profile Class (Responsible for mapping).
๐๐ฎ๐๐๐ญ ๐๐๐๐ค๐๐ ๐๐ฌ
โถ AutoMapper
โถ Microsoft.Extensions.DependencyInjection
There is debate over use of mapperย , where do you stand in support of mappers or against and whyย ? โ ๐ฝ
If you like my work you can help me in growing through following ways
Subscribe my Weeklyย .NET Newsletter where I would be publishing one tip on C#/.NET on weekly basis.
You can Buy a Coffee for me.