FlexMapper.DependencyInjection 1.0.3

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

FlexMapper

FlexMapper is a lightweight object-mapping library for .NET 8.

It maps objects by convention and lets you configure reverse mapping, custom members, ignored members, lists, arrays, nested objects, and type converters.

Structure

src/
  FlexMapper/                    Core library
  FlexMapper.DependencyInjection/ ASP.NET Core DI integration
samples/
  ConsoleSample/                 Simple console example
tests/
  FlexMapper.Tests/              Automated xUnit tests
  FlexMapper.Real/               Real projects that validate NuGet usage
docs/
  getting-started.md             Usage guide
  packaging.md                   Building and consuming local packages
  architecture.md                Architecture overview
  roadmap.md                     Next steps
release/                         Output of the generated NuGet packages

Install

Core package:

dotnet add package FlexMapper

ASP.NET Core integration:

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);

ASP.NET Core

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

Profiles (organize mappings in classes)

To avoid centralizing everything in the builder, group your mappings in classes that inherit from FlexMapperProfile 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();

        cfg.AddConverter<bool, string>(value => value ? "SIM" : "NAO");
    }
}

Registration in ASP.NET Core:

// Scans the assembly and applies every FlexMapperProfile found
builder.Services.AddFlexMapper(typeof(ProdutoMapping).Assembly);

// Multiple assemblies
builder.Services.AddFlexMapper(AppDomain.CurrentDomain.GetAssemblies());

// Profiles plus additional inline configuration
builder.Services.AddFlexMapper(cfg =>
{
    cfg.AddConverter<bool, string>(value => value ? "SIM" : "NAO");
}, typeof(ProdutoMapping).Assembly);

The scan skips abstract types and requires a parameterless constructor. All profiles share the same configuration, resulting in a single IFlexMapper singleton.

Custom member

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

Ignore a member

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

Custom converter

cfg.AddConverter<string, bool>(value =>
{
    if (string.IsNullOrWhiteSpace(value))
        return false;

    return value.Equals("SIM", StringComparison.OrdinalIgnoreCase)
        || value.Equals("S", StringComparison.OrdinalIgnoreCase)
        || value.Equals("TRUE", StringComparison.OrdinalIgnoreCase)
        || value.Equals("1");
});

Dates

FlexMapper converts strings to DateTime and DateOnly using InvariantCulture, the current culture, and pt-BR.

Accepted example:

Cadastro = "20/06/2026 14:20:38"

Build and test

build.cmd

Or manually:

dotnet restore FlexMapper.slnx
dotnet build FlexMapper.slnx --configuration Release
dotnet test tests/FlexMapper.Tests/FlexMapper.Tests.csproj --configuration Release

Generate packages

pack.cmd

The packages are generated in:

release/

The real project in tests/FlexMapper.Real has a nuget.config pointing to that folder.

Features

  • Mapping by convention
  • Reverse mapping
  • Profiles (mappings organized in classes)
  • Public properties and fields
  • Custom member mapping
  • Ignored members
  • Lists and arrays
  • Nullable
  • Enum
  • Guid
  • DateTime
  • DateOnly
  • TimeOnly
  • Nested objects
  • Custom converters
  • ASP.NET Core dependency injection integration
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.