MegaMapper 1.0.0

dotnet add package MegaMapper --version 1.0.0
                    
NuGet\Install-Package MegaMapper -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MegaMapper" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MegaMapper" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MegaMapper" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MegaMapper --version 1.0.0
                    
#r "nuget: MegaMapper, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MegaMapper@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MegaMapper&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MegaMapper&version=1.0.0
                    
Install as a Cake Tool

Everyone in their life at a certain point needed a mapping library. Every mapping library is a mess to deal with, this is also a mess, but less.

This library was born to meet our needs to have asyncronus DI compatible mappings.

Features

Everything you need from you mapper plus:

  • Simple object-to-object mapping without declaring maps
  • Asynchronous mapping functions with DI

Usage

The project demonstrates how to configure the DI container to register the MegaMapper and your custom mapping profiles or builders.

Example of configuring DI in tests or your application:

var services = new ServiceCollection();
services.AddMegaMapper();

//Optional custom builders:
services.AddMegaMapperBuilder<YourCustomMapBuilder>();
//Optional custom converters:
services.AddMegaMapperProfile<YourCustomProfile>();

You can then use the mapper to map objects asynchronously:

var dto = await mapper.Map<YourDto>(yourEntity);

Advanced example: using a service in an async mapping

The AdvancedMappingProfile example shows how to inject a service via Dependency Injection and use it inside an asynchronous mapping configuration.

Profile Implementation

public class AdvancedMappingBuilder : MegaMapperMapBuilder<UserComplex, UserComplexDto>
{
    private readonly ICustomService _customService;

    //Every property is map with the base core mapping, then overrided with the properties defined here.
    public override bool UseBaseMap => true;

    public AdvancedMappingBuilder(ICustomService customService)
    {
        _customService = customService;

        MapField<string, string>(x => x.FirstName, y => y.FirstName, async (a, b, c) => await _customService.GetTheData());
    }
}

Inject the map:

services.AddMegaMapperBuilder<AdvancedMappingBuilder>();

Then use the map

var dto = await _mapper.Map<UserComplexDto>(user);

Custom profiles

If you need more flexibility you can also use a custom profile to define the entire logic:

public class AdvancedMappingProfile : MegaMapperProfile<UserComplex, UserComplexDto>
{
    private readonly ICustomService _customService;
    public AdvancedMappingProfile(ICustomService customService)
    {
        _customService = customService;
    }
    protected override async Task<UserComplexDto> Map(UserComplex input, UserComplexDto output)
    {
        output.FirstName = await _customService.GetTheData();
        return output;
    }

    protected override Task<UserComplex> MapBack(UserComplexDto input, UserComplex output)
    {
        return Task.FromResult(output);
    }
}

Inject the map:

services.AddMegaMapperProfile<AdvancedMappingProfile>();

Then use the map

var dto = await _mapper.Map<UserComplexDto>(user);

Define only the custom mapping for certain properties

In certains scenarios, you could have the need to custom-map only one property, then keep all the others in a one to one mapping. You can use a custom profile or custom bulder as above, and then override the property UseBaseMap, if set to true, before applying any of the maps, the core proceed to apply the embedded automap.

More examples

The repository contains comprehensive xUnit tests covering:

  • Simple mapping between entities and DTOs
  • Mapping with nested objects and collections
  • Asynchronous mapping scenarios
  • Type conversions
  • Bidirectional mapping validation

You can watch these for examples.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 142 8/11/2025

First release