Eslam HelmyEslam Helmy
4 min readEslam

🛠️ AutoMapper Goes Commercial — Here’s Your Best Alternative


🛠️ AutoMapper Goes Commercial — Here’s Your Best Alternative

When AutoMapper announced its shift to a commercial model, developers were left wondering: What now? Should you stick with the last free version, pay for the license, build your own mappers, or switch to an alternative? Let’s break it down and explore the best path forward for your project. 🌟

Why Not Stick with AutoMapper 14.0.0? 🤔

While it might seem tempting to freeze your project at the last free version (14.0.0), this approach has significant drawbacks:

  • Compatibility Risks: Future updates to .NET may break functionality or leave you without access to new features.
  • Security Concerns: Without ongoing support, you risk vulnerabilities and bugs that won’t be patched.

This makes sticking with the old version a risky long-term strategy.

Building Your Own Mappers: Pros and Cons 🛠️

Creating custom mappers might seem like a straightforward solution. After all, it gives you full control over your code and avoids external dependencies. However:

Pros:

  • Transparency: No hidden “magic” behind the scenes.
  • Customizability: Tailor mapping logic precisely to your needs.

Cons:

  • Time-Consuming: Writing and maintaining mappers for every object can become tedious.
  • Error-Prone: Manual mapping increases the likelihood of mistakes, especially in large projects.

While this approach works for small projects or teams with strict requirements, it’s often impractical for larger, evolving applications.

Why Not Just Pay for AutoMapper? 💳

Really?

Switch to an alternative? 🌟

You might worry, “What if this alternative also goes commercial?” It’s a valid concern, but open-source thrives on diversity. If one tool becomes paid, others will emerge. This flexibility ensures you’re never locked in.


Enter Mapster: A Powerful Alternative 🌟

If you’re looking for a modern alternative to AutoMapper, Mapster is a strong contender. Here’s why developers are flocking to it:

Key Features:

  • Performance: Mapster is significantly faster than AutoMapper, particularly for large datasets.
  • Minimal Configuration: It supports convention-based mapping but allows for custom configurations when needed.
  • Flexibility: Offers both dependency injection (DI) and static mapping options.

How to Migrate from AutoMapper to Mapster 🚀

Switching libraries might sound daunting, but it doesn’t have to be! Here’s a step-by-step guide to make the transition painless:

1️⃣ Install Mapster and Remove AutoMapper

Start by adding Mapster and removing AutoMapper:

dotnet add package Mapster  
dotnet add package Mapster.DependencyInjection  
dotnet remove package AutoMapper

Removing AutoMapper ensures you identify all impacted files during migration.

2️⃣ Inject Mapster Services

Set up Mapster in your project’s Program.cs or Startup.cs:

builder.Services.AddMapster();

3️⃣ Convert Custom Configurations

Types Without Custom Logic

In AutoMapper, you’re required to define mappings even if no custom logic is applied:

// Simple DTO: No config needed since names match  
CreateMap<User, UserSimpleDto>();

In Mapster, you can skip this entirely — no configuration is needed for straightforward mappings where property names match.

Types With Custom Configurations

For mappings that involve custom logic, you’ll need to convert AutoMapper configurations into Mapster-compatible ones. Here’s an example:

AutoMapper Configuration:

// Detailed DTO: Requires custom mapping  
CreateMap<User, UserDetailedDto>()  
    .ForMember(dest => dest.FullName,   
        opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}"))  
    .ForMember(dest => dest.Age,   
        opt => opt.MapFrom(src => DateTime.Now.Year - src.DateOfBirth.Year));

Mapster Configuration:

No profile is needed, just centralize your configurations in a static method that should be called from your program file

public static class MappingConfig  
{  
    public static void RegisterMappings()  
    {  
        TypeAdapterConfig<User, UserDetailedDto>.NewConfig()  
            .Map(dest => dest.FullName, src => $"{src.FirstName} {src.LastName}")  
            .Map(dest => dest.Age, src => DateTime.Now.Year - src.DateOfBirth.Year);  
    }  
}  
  
// Call this configuration in Program.cs or Startup.cs  
MappingConfig.RegisterMappings();

Use AI tools like ChatGPT or Claude to convert existing AutoMapper profiles into Mapster configurations quickly.

4️⃣ Replace Usages of IMapper

Update all references from AutoMapper to Mapster Use search-and-replace in all files.

//replace using ctrl h  
using AutoMapper;
// with
using MapsterMapper;

5️⃣ Test Thoroughly

Run regression tests or automated tests to ensure everything works as expected after migration.


Bonus Tip: Stay Consistent 🏗️

While Mapster allows quick static mapping via its Adapt method:

var userDto = user.Adapt<UserDto>();

It’s better to stick with dependency injection-based mapping (IMapper) for consistency in team projects and larger applications. This approach ensures predictable workflows and simplifies testing.

Thanks for reading!

Share this post