HostLoom.Mapping 0.2.0

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

HostLoom.Mapping

HostLoom.Mapping is a small, explicit alternative to runtime convention mappers. A map is an ordinary C# class, so member access, nullability, constructor choice, and conversions are checked by the compiler. Mapping performs no assembly scanning, reflection-based member mapping, expression compilation, runtime code generation, or global configuration.

The core package has no dependency-injection dependency. Install HostLoom.Mapping.DependencyInjection to register map classes with the built-in .NET container.

public sealed record Customer(string Name, Address Address);
public sealed record CustomerDto(string Name, string City);

public sealed class CustomerMapper : IMapper<Customer, CustomerDto>
{
    public CustomerDto Map(Customer source) =>
        new(source.Name, source.Address.City);
}

services.AddHostLoomMapping(mapping =>
    mapping.Add<Customer, CustomerDto, CustomerMapper>());

// Prefer the closed mapper when only this pair is needed.
var customerMapper = provider.GetRequiredService<IMapper<Customer, CustomerDto>>();
var dto = customerMapper.Map(customer);

// Or use the dispatcher when an orchestration maps several pairs. It is scoped, so resolve it
// from a scope — a request, a delivery, or an explicit CreateScope.
using var scope = provider.CreateScope();
var mapper = scope.ServiceProvider.GetRequiredService<IMapper>();
var sameDto = mapper.From(customer).To<CustomerDto>();

IMapper is registered scoped, which has two consequences worth knowing before the first run. Resolving it from the root provider throws once scope validation is on — the default for the generic host in Development, so this fails there and would have succeeded in Production. For the same reason it cannot be constructor-injected into a singleton; inject the closed IMapper<TSource, TDestination> there, or take IServiceScopeFactory and resolve per unit of work. Closed maps registered with the default transient lifetime have neither restriction.

Maps are transient by default so constructor-injected scoped dependencies remain safe. Choose a different ServiceLifetime only when its dependency graph supports that lifetime. A singleton map instance can also be registered explicitly. Container-created map classes expose a public constructor. Duplicate type pairs fail during registration, and a missing pair throws MappingNotFoundException with both requested types.

Design rules

  • Use different destination types for semantically different views instead of selecting a hidden named profile for the same pair.
  • Keep mapping synchronous and deterministic. Fetch or enrich data outside the map.
  • Inject a closed IMapper<TSource, TDestination> into focused consumers. Use IMapper only when coordinating multiple pairs.
  • Write database projections directly as IQueryable.Select expressions so the provider sees the complete expression tree; do not materialize records merely to pass them through a mapper.
  • Treat null as an application decision. The contracts require non-null inputs; represent a nullable result explicitly in the destination model when that is meaningful.
  • Prefer immutable destination records and constructor mapping. Required members and constructors make incomplete mappings compile-time failures.

Both packages target .NET 10, enable the SDK's Native AOT and trimming analyzers, and keep the map dispatch path free of reflection and dynamic code generation.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on HostLoom.Mapping:

Package Downloads
HostLoom.Mapping.DependencyInjection

Microsoft.Extensions.DependencyInjection registration for HostLoom mapping.

HostLoom.Mapping.Testing

Container-free mapper composition for testing HostLoom mapping consumers.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.17.0 75 10/25/2026
0.16.1 95 10/22/2026
0.16.0 187 10/14/2026
0.15.1 131 10/12/2026
0.15.0 199 10/4/2026
0.14.0 125 10/4/2026
0.13.0 160 9/28/2026
0.12.0 146 9/27/2026
0.11.0 152 9/25/2026
0.10.0 151 9/22/2026
0.9.0 129 9/22/2026
0.8.0 150 9/19/2026
0.7.0 147 9/17/2026
0.6.0 145 9/6/2026
0.5.0 135 9/5/2026
0.4.0 138 9/3/2026
0.3.0 146 8/28/2026
0.2.0 134 8/27/2026