Infrastructure.Mapping 1.0.0

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

About

The Infrastructure.Mapping package provides a flexible object mapping mechanism for transforming data between application layers (e.g., database entities to API models), supporting:

a) Simple TSource → TDestination transformations;
b) Mapping with additional data (TData);
c) Collection processing.

How to Use

  1. Define Entities and Models

Entities (from DB):

public class DepartmentEntity
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
}

public class EmployeeEntity
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public int DepartmentId { get; set; }
}

Models (for API):

public class DepartmentModel
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
    public IReadOnlyCollection<EmployeeModel> Employees { get; set; } = [];
}

public class EmployeeModel
{
    public int Id { get; set; }
    public string Name { get; set; } = string.Empty;
}
  1. Create Mappers

Employee mapper (simple mapping):

public class EmployeeMapper : IMapper<EmployeeEntity, EmployeeModel>
{
    public EmployeeModel Map(EmployeeEntity source)
    {
        ArgumentNullException.ThrowIfNull(source, nameof(source));
        return new EmployeeModel
        {
            Id = source.Id,
            Name = source.Name
        };
    }
}

Department mapper (mapping with employee data):

public class DepartmentMapper : IDataMapper<DepartmentEntity, DepartmentModel, EmployeeEntity>
{
    private readonly IMapper<EmployeeEntity, EmployeeModel> _employeeMapper;

    public DepartmentMapper(IMapper<EmployeeEntity, EmployeeModel> employeeMapper)
    {
        _employeeMapper = employeeMapper;
    }

    public DepartmentModel Map(DepartmentEntity departmentEntity, 
        IEnumerable<EmployeeEntity> employeeEntities)
    {
        var employees = _employeeMapper.Map(
            employeeEntities.Where(e => e.DepartmentId == departmentEntity.Id)
        );

        return new DepartmentModel
        {
            Id = departmentEntity.Id,
            Name = departmentEntity.Name,
            Employees = employees
        };
    }
}
  1. Apply Mapping

Simple code:

    // Source data
    var employees = new List<EmployeeEntity>
    {
        new EmployeeEntity { Id = 1, Name = "Employee1", DepartmentId = 1 },
        new EmployeeEntity { Id = 2, Name = "Employee2", DepartmentId = 1 },
    };

    var departments = new List<DepartmentEntity>
    {
        new DepartmentEntity { Id = 1, Name = "Department1" },
        new DepartmentEntity { Id = 2, Name = "Department2" }
    };

    // Create mappers
    var employeeMapper = new EmployeeMapper();
    var departmentMapper = new DepartmentMapper(employeeMapper);

    // Map collections
    var departmentModels = departmentMapper.Map(departments, employees);

Result:

The departmentModels collection contains DepartmentModel objects, where each department includes its employees.

Main Types

The main types provided by this library are:

Infrastructure.Mapping.Interfaces.IMapper<TSource, TDestination>
    *(Defines a contract for mapping objects from one type to another. 
        Supports simple one‑to‑one transformations)*
Infrastructure.Mapping.Interfaces.IDataMapper<TSource, TDestination, TData>
    *(Extends basic mapping with support for additional data (TData). 
        Useful when transformation logic depends on external context or related entities.)*
Infrastructure.Mapping.Extensions.CollectionMappingExtensions
    *(Static class providing extension methods for IMapper and IDataMapper. 
        Enables bulk mapping of collections to IReadOnlyCollection<TDestination>.)*

Feedback & Contributing

Infrastructure.Mapping is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Infrastructure.Mapping:

Package Downloads
Infrastructure.Mapping.AutoMapper

The package providing core components for object mapping using packet Automapper in applications. Simplifies mapping implementation by offering reusable abstractions and helpers. Enables developers to focus on business logic rather than low‑level mapping details. Future updates will expand functionality with additional utilities and mapping patterns.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 141 1/5/2026