Muonroi.Mapper 1.0.0-alpha.16

This is a prerelease version of Muonroi.Mapper.
dotnet add package Muonroi.Mapper --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.Mapper -Version 1.0.0-alpha.16
                    
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="Muonroi.Mapper" Version="1.0.0-alpha.16" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Muonroi.Mapper" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.Mapper" />
                    
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 Muonroi.Mapper --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.Mapper, 1.0.0-alpha.16"
                    
#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 Muonroi.Mapper@1.0.0-alpha.16
                    
#: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=Muonroi.Mapper&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.Mapper&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

Muonroi.Mapper

Convention-based object mapper for Muonroi services — assembly-scanned registration, compiled expression-tree mapping, and zero-configuration DI wiring.

NuGet License: Apache 2.0

Muonroi.Mapper replaces hand-written mapping boilerplate with a lightweight, reflection-based engine. Mark a DTO with IMapFrom<TSource> and call ConfigureMapper() once at startup — the library scans the assembly, builds compiled Expression-tree mapping actions for every matched property pair, caches them in MappingConfiguration, and registers IMapper → SimpleMapper in the DI container.

Installation

dotnet add package Muonroi.Mapper --prerelease

Quick Start

1. Mark the DTO

using Muonroi.Core.Abstractions.Interfaces;

public sealed class ProductDto : IMapFrom<Product>
{
    public Guid    Id            { get; set; }
    public string  Name          { get; set; } = string.Empty;
    public decimal Price         { get; set; }
    public int     StockQuantity { get; set; }
}

2. Register at startup

using System.Reflection;
using Muonroi.Mapper.Mapper;

builder.Services.ConfigureMapper(Assembly.GetExecutingAssembly());

Omit the Assembly parameter to scan every assembly loaded in the current AppDomain.

3. Inject and map

using Muonroi.Mapper.Mapper;

public sealed class MappingController(IMapper mapper) : ControllerBase
{
    [HttpPost("to-dto")]
    public IActionResult ToDto([FromBody] Product product)
    {
        ProductDto dto = mapper.Map<ProductDto>(product);   // new destination instance
        return Ok(dto);
    }

    [HttpPost("onto-existing")]
    public IActionResult OntoExisting([FromBody] Product product)
    {
        ProductDto existing = new();
        ProductDto result = mapper.Map<Product, ProductDto>(product, existing);  // merge onto existing
        return Ok(result);
    }
}

Features

  • Assembly-scan registrationConfigureMapper(params Assembly[]) discovers every type implementing IMapFrom<T> and auto-registers both directions (Source → Destination and Destination → Source).
  • Compiled expression trees — mapping actions are built once via System.Linq.Expressions and cached in a ConcurrentDictionary; subsequent calls pay only a delegate invoke.
  • Property-name convention — writable destination properties are matched by name to readable source properties; type-assignability is checked; unmatched properties are silently skipped.
  • Three mapping overloads — create a new destination (Map<TDestination>(source)), merge onto an existing instance (Map<TSource, TDestination>(source, destination)), or use the non-generic Map(object, object) overload.
  • Single DI callConfigureMapper() registers both MappingConfiguration (singleton) and IMapper → SimpleMapper (singleton) in one extension method.

Configuration

There are no appsettings keys or options classes. All configuration is done through the ConfigureMapper call:

// Scan a specific set of assemblies (recommended for startup performance)
builder.Services.ConfigureMapper(
    Assembly.GetExecutingAssembly(),
    typeof(SomeOtherMarker).Assembly);

// Scan every loaded assembly (convenient; slightly slower at startup)
builder.Services.ConfigureMapper();

API Reference

Type Purpose
IMapper (Muonroi.Mapper.Mapper) Primary mapping contract — three Map overloads
SimpleMapper Singleton IMapper implementation backed by MappingConfiguration
MappingConfiguration Thread-safe cache of compiled Action<object, object> mapping delegates, keyed by (Source, Destination) type pair
MapperServiceCollectionExtensions.ConfigureMapper DI registration extension — scans assemblies for IMapFrom<T>, populates MappingConfiguration, registers IMapper
IMapFrom<T> (Muonroi.Core.Abstractions) Marker interface applied to destination types to declare the source type for auto-discovery

Samples

  • Quickstart.Mapper — end-to-end ASP.NET Core API demonstrating IMapFrom<T> declaration, ConfigureMapper registration, and both Map overloads via two controller endpoints

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS)

License

Apache-2.0. See LICENSE-APACHE for the full text.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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 (3)

Showing the top 3 NuGet packages that depend on Muonroi.Mapper:

Package Downloads
Muonroi.Mediator

Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration.

Muonroi.AspNetCore

ASP.NET Core integration: auto-CRUD controllers, middleware pipeline, license protection, and Muonroi hosting extensions.

Muonroi.BuildingBlock.All

Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 100 6/22/2026
1.0.0-alpha.15 178 5/31/2026
1.0.0-alpha.14 172 5/15/2026
1.0.0-alpha.13 145 5/2/2026
1.0.0-alpha.12 105 4/2/2026
1.0.0-alpha.11 145 4/2/2026
1.0.0-alpha.9 84 3/30/2026
1.0.0-alpha.8 329 3/28/2026
1.0.0-alpha.7 82 3/27/2026
1.0.0-alpha.5 69 3/27/2026
1.0.0-alpha.4 86 3/27/2026
1.0.0-alpha.3 75 3/27/2026
1.0.0-alpha.2 74 3/26/2026
1.0.0-alpha.1 104 3/8/2026