FlexMapper.DependencyInjection 1.1.1

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

FlexMapper

A lightweight, fast object-mapping library for .NET 8, 9 and 10.

FlexMapper maps objects by convention and lets you configure reverse mapping, custom members, ignored members, lists, arrays, nested objects, and type converters — with a compiled engine that is faster than AutoMapper on simple objects and allocates no more than AutoMapper.

Install

dotnet add package FlexMapper

ASP.NET Core integration (optional):

dotnet add package FlexMapper.DependencyInjection

Basic usage

var config = new MapperConfiguration();

config.Map<Produto, ProdutoDto>()
      .Reverse();

var mapper = config.Build();

var dto = mapper.To<ProdutoDto>(produto);
var domain = mapper.To<Produto>(dto);

IFlexMapper (the result of Build()) is immutable and thread-safe: build once, share it, map concurrently.

ASP.NET Core

builder.Services.AddFlexMapper(cfg =>
{
    cfg.Map<Produto, ProdutoDto>()
       .Reverse();
});

Then inject IFlexMapper where you need it. It is registered as a singleton.

Profiles

Group mappings in classes and register them by scanning assemblies (the same workflow as AddAutoMapper):

public sealed class ProdutoMapping : FlexMapperProfile
{
    public override void Configure(MapperConfiguration cfg)
    {
        cfg.Map<Produto, ProdutoDto>()
           .For(dest => dest.CategoriaNome, src => src.Categoria!.Descricao)
           .Reverse();
    }
}

builder.Services.AddFlexMapper(typeof(ProdutoMapping).Assembly);

Custom member and ignore

cfg.Map<Pessoa, PessoaDto>()
   .For(dest => dest.Nome, src => src.NomeCompleto)
   .Reverse();

cfg.Map<Usuario, UsuarioDto>()
   .Ignore(dest => dest.SenhaHash);

Custom converter

cfg.AddConverter<string, bool>(value =>
    value.Equals("YES", StringComparison.OrdinalIgnoreCase) || value == "1");

Validate the configuration

Fail fast on broken maps at startup or in tests instead of at request time. It throws a single MapException listing every problem (source, destination and member).

config.ValidateConfiguration();                              // lenient (default)
config.ValidateConfiguration(FlexValidationMode.Strict);     // also require every member to have a source

Note that FlexMapper maps by convention even for pairs you never registered, so a forgotten Map<Domain, Dto>() yields a DTO with unfilled members instead of an error — and validation cannot see unregistered pairs. Set RequireConfiguredMaps to make that fail loudly:

var config = new MapperConfiguration { RequireConfiguredMaps = true };
// mapping an unregistered pair (including nested members and collection elements) now throws

In ASP.NET Core, set it inside the configuration callback (the assemblies-only overload of AddFlexMapper gives you nowhere to set it):

builder.Services.AddFlexMapper(cfg =>
{
    cfg.RequireConfiguredMaps = true;                       // a forgotten map fails at map time
    cfg.ValidateConfiguration(FlexValidationMode.Strict);   // a member without a source fails at startup
}, typeof(ProdutoMapping).Assembly);

Dates and nullable

Strings convert to DateTime, DateOnly and TimeOnly (and their nullable variants) using invariant, current and pt-BR cultures. Accepted formats include 20/06/2026, 20/06/2026 14:30 and 2026-06-20.

Null nullable values are preserved; a null mapped onto a non-nullable destination yields default(T) — mapping never throws just because a source was null.

Security

Mapping happens by convention, so sensitive members flow automatically unless you stop them. Ignore password hashes, tokens, roles and audit fields on the maps that touch them, and prefer dedicated input DTOs — mapping client input straight onto entities (e.g. via Reverse()) enables over-posting.

cfg.Map<UsuarioEntrada, Usuario>()
   .Ignore(dest => dest.Id)
   .Ignore(dest => dest.Role)
   .Ignore(dest => dest.SenhaHash);

Performance

The engine compiles the whole per-type mapping into a typed delegate, caches a mapping plan per type pair, memoizes the conversion strategy, and runs a JIT-specialized typed collection loop.

Scenario Manual AutoMapper FlexMapper
Simple object 5 ns 54 ns 19 ns
Nested object 24 ns 79 ns 78 ns
List of 1,000 7.7 µs 8.5 µs 9.7 µs
List of 10,000 83 µs 154 µs 103 µs

FlexMapper is faster than AutoMapper on simple objects (~2.9x) and large lists (~1.5x), ties on nested objects and smaller lists, and allocates exactly what manual mapping allocates — AutoMapper allocates 13–28% more.

Features

  • Mapping by convention; reverse mapping; profiles
  • Public properties and fields
  • Custom member mapping, ignored members, custom converters
  • Lists, arrays and nested objects
  • Nullable, enum, Guid, DateTime, DateOnly, TimeOnly
  • Configuration validation and optional required maps
  • Compiled, thread-safe mapper
  • ASP.NET Core dependency injection integration

Requirements

.NET 8, 9 or 10.

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 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 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.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.