gitmyhub

AutoMapper

C# ★ 10k updated 2d ago

A convention-based object-object mapper in .NET.

A .NET library that automatically copies data between objects with matching property names, eliminating repetitive hand-written conversion code between database models and API response objects.

C#.NETASP.NET CoreNuGetsetup: moderatecomplexity 2/5

AutoMapper is a library for .NET developers that automates a tedious but common programming task: copying data from one object to another when both objects represent the same information but have different shapes. In a typical .NET application, you might have a database model called Foo and a separate data transfer object called FooDto, and you need to convert between them constantly. Writing that conversion code by hand is repetitive and error-prone. AutoMapper generates it for you based on naming conventions.

The way it works is that you declare at startup which types you want to map between, and AutoMapper figures out how to move data between matching properties automatically. When two properties have the same name, it maps them without any extra configuration. For cases where the names differ or the data needs to be transformed, you can provide custom rules. Once configured, a single method call converts one object into the other at runtime.

Installing it is straightforward: it is available as a NuGet package and can be added to any .NET project with one command. It integrates with the standard .NET dependency injection system used in ASP.NET Core applications, so it fits naturally into most modern .NET codebases. There are also extension packages for additional scenarios like mapping with Entity Framework, LINQ expression trees, and enumerations.

The project now requires a license key for use, which can be registered at AutoMapper.io. The README notes this and shows where to set the key in the configuration. For questions, the project points to Stack Overflow and official documentation. Paying customers have access to direct support.

Where it fits