DomainMapper 1.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package DomainMapper --version 1.2.0
                    
NuGet\Install-Package DomainMapper -Version 1.2.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="DomainMapper" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DomainMapper" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="DomainMapper" />
                    
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 DomainMapper --version 1.2.0
                    
#r "nuget: DomainMapper, 1.2.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 DomainMapper@1.2.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=DomainMapper&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=DomainMapper&version=1.2.0
                    
Install as a Cake Tool

DomainMapper

NuGet NuGet downloads

Map data. Preserve invariants.

DomainMapper is a small compile-time mapper for .NET with a domain-driven design bias. Its source generator emits direct C# and does not use runtime reflection. Version 1.2.0 adds opt-in collection policies, reference preservation, runtime dispatch, and query projections while retaining domain-owned constructors and factories.

Version 1.2.0

Install DomainMapper from NuGet with:

dotnet add package DomainMapper --version 1.2.0

Domain-first mapping

using DomainMapper.Abstractions;

[DomainMapper]
public static partial class OrderMapper
{
    [DomainFactory(Input = DomainFactoryInput.Source)]
    private static OrderId ToOrderId(int value) => new(value);

    [MapToFactory(nameof(Order.Place))]
    public static partial Order Place(OrderDraft source);
}

[MapToFactory] makes the target-owned factory mandatory. DomainMapper binds source properties and additional mapping parameters to factory parameters by name and applies mapper-owned [DomainFactory] conversions where their source and target types match. Explicit mapping parameters take precedence over same-named root source properties. If the target cannot be constructed completely, generation fails instead of bypassing the domain boundary or silently dropping state.

Supported mappings

DomainMapper 1.2.0 supports:

  • mutable targets with accessible parameterless constructors;
  • immutable targets and records with accessible constructors;
  • target-owned static factories through [MapToFactory];
  • mapper-owned source-value and member-bound conversions through [DomainFactory];
  • nested objects, arrays, lists, read-only collection targets, and mutable or read-only dictionary interfaces;
  • existing-target property updates;
  • explicit property and field renames, including nested source paths;
  • typed computed target members and additional mapping parameters;
  • target/source completeness, typed ignores, and allow-listed partial updates;
  • conditional and null-aware assignments with constant substitution;
  • typed completion hooks, mapping composition, and bounded recursion;
  • Replace, ClearAndFill, and Append policies for existing-target collections;
  • invocation-local reference preservation for mutable cyclic graphs;
  • closed-world generated runtime dispatch with explicit derived-source opt-in;
  • cached provider-neutral expression projections through the separate DomainMapper.Projections contract package;
  • nested and generic mapper types and generic mapping methods;
  • direct generated code that enumerates general sequences and preallocates only when the source exposes a count.

Fields participate when they are named by an explicit mapping contract; convention mapping remains property-only for compatibility. See the authoritative capabilities and limitations and versioned changelog.

Construction is fail-closed: every accessible writable target member must be mapped, and source-matched target state that is not writable from the generated mapper is rejected with DMPR101.

Unsupported projection or tracking shapes fail at build time. Private-member mutation remains unsupported, and no feature scans assemblies, infers persistence semantics, or introduces mutable runtime mapping configuration.

Build and test

dotnet restore DomainMapper.slnx -p:HUSKY=0
dotnet build DomainMapper.slnx --configuration Release --no-restore -p:HUSKY=0
dotnet test test/DomainMapper.Tests/DomainMapper.Tests.csproj --configuration Release --no-build -p:HUSKY=0

Run the sample with:

dotnet run --project samples/DomainMapper.Sample/DomainMapper.Sample.csproj

Benchmarks

The comparison suite pins Mapperly 4.3.1 and measures both generated runtime mappings and cold source generation in balanced execution orders.

DOMAINMAPPER_BENCHMARK_PAIRS=6 ./scripts/run-stable-benchmarks.sh

See the benchmark methodology.

Project layout

  • src/DomainMapper.Abstractions — public, compile-time mapping attributes and policy types.
  • src/DomainMapper.Projections — optional provider-neutral projection declaration contract.
  • src/DomainMapper/Engine — contract discovery, semantic planning, conversion policy, and C# emission.
  • test/DomainMapper.Tests — engine contract and performance-gate tests.
  • benchmarks/DomainMapper.Benchmarks — balanced DomainMapper-versus-Mapperly evidence.
  • samples/DomainMapper.Sample — aggregate construction through a domain factory.

License

DomainMapper is licensed under Apache-2.0. Third-party attribution is retained in NOTICE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on DomainMapper:

Package Downloads
DomainMapper.Projections

Provider-neutral expression-tree projections for DomainMapper.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.2.1 91 8/20/2026
1.2.0 100 8/15/2026
1.1.0 258 8/15/2026
1.0.0 134 8/13/2026

Added

Explicit Replace, ClearAndFill, and Append policies for existing-target collections.

Invocation-local reference preservation for shared and cyclic mutable object graphs.

Closed-world runtime dispatch through generated TryMapRuntime and MapRuntime methods.

Cached provider-neutral expression projections through the optional DomainMapper.Projections package.

Diagnostics DMPR105 through DMPR107 for unsupported tracking, projection, and registry declarations.

Incremental invalidation, concurrency, trimming, and native AOT validation fixtures.

Changed

Incremental generator inputs are fingerprinted per mapper and reachable source contract, keeping isolated changes from invalidating unrelated mapper outputs.

The 1.2 packages validate public API compatibility against the 1.1 release.

Fixed

Reference tracking now distinguishes target contracts when one source instance participates in heterogeneous target shapes.

Projection generation rejects failed mappings, custom delegates, and user-defined conversion calls while retaining pure lifted conversions.

Runtime registries reject open-world interface ambiguity and value-type derived dispatch, handle nullable annotations, and exclude mappings whose deferred helpers fail.

Incremental invalidation includes containing partial types and inherited mapper declarations that affect emitted source.

Full changelog: https://github.com/skuirrels/DomainMapper/compare/v1.1.0...v1.2.0