Muonroi.Mapper
1.0.0-alpha.16
dotnet add package Muonroi.Mapper --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Mapper -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Mapper" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Mapper" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Mapper" />
paket add Muonroi.Mapper --version 1.0.0-alpha.16
#r "nuget: Muonroi.Mapper, 1.0.0-alpha.16"
#:package Muonroi.Mapper@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Mapper&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Mapper&version=1.0.0-alpha.16&prerelease
Muonroi.Mapper
Convention-based object mapper for Muonroi services — assembly-scanned registration, compiled expression-tree mapping, and zero-configuration DI wiring.
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 registration —
ConfigureMapper(params Assembly[])discovers every type implementingIMapFrom<T>and auto-registers both directions (Source → DestinationandDestination → Source). - Compiled expression trees — mapping actions are built once via
System.Linq.Expressionsand cached in aConcurrentDictionary; 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-genericMap(object, object)overload. - Single DI call —
ConfigureMapper()registers bothMappingConfiguration(singleton) andIMapper → 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,ConfigureMapperregistration, and bothMapoverloads via two controller endpoints
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS)
Related Packages
Muonroi.Core.Abstractions— definesIMapFrom<T>consumed by this package's assembly scanner
License
Apache-2.0. See LICENSE-APACHE for the full text.
| Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
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 |