OnMapper 2.0.0

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

OnMapper

NuGet Downloads License

A high-performance, lightweight object mapper for .NET that simplifies mapping between Data Transfer Objects (DTOs) and domain models. OnMapper supports nested objects, collections, and async operations with minimal configuration.

✨ Features

  • 🚀 High Performance - Optimized reflection with caching for fast mappings
  • 🎯 Simple API - Easy to use with minimal configuration
  • 🔄 Nested Objects - Automatically maps nested objects and complex hierarchies
  • 📦 Collections - Built-in support for lists, arrays, and enumerables
  • Async/Await - Fully asynchronous API
  • 🎨 Multi-Framework - Supports .NET 6, 7, 8, and 9
  • 💪 Type-Safe - Strongly typed with full nullable reference type support
  • 📝 Result Pattern - Built-in result type for error handling

📦 Installation

Install via NuGet Package Manager:

dotnet add package OnMapper

Or via Package Manager Console:

Install-Package OnMapper

🚀 Quick Start

Basic Mapping

using OnMapper;
using OnMapper.Services.Interfaces;

// Create mapper instance
IMappingService mapper = new OnMapping();

// Define your models
public class UserDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

public class UserEntity
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Email { get; set; }
}

// Map single object
var userDto = new UserDto { Id = 1, Name = "John Doe", Email = "john@example.com" };
var result = await mapper.Map<UserDto, UserEntity>(userDto);

if (result.IsSuccess)
{
    var userEntity = result.Data;
    Console.WriteLine($"Mapped: {userEntity.Name}");
}
else
{
    Console.WriteLine($"Error: {result.Message}");
}

Collection Mapping

// Map collections
var userDtos = new List<UserDto>
{
    new UserDto { Id = 1, Name = "John Doe", Email = "john@example.com" },
    new UserDto { Id = 2, Name = "Jane Smith", Email = "jane@example.com" }
};

var result = await mapper.MapCollection<UserDto, UserEntity>(userDtos);

if (result.IsSuccess)
{
    foreach (var user in result.Data)
    {
        Console.WriteLine($"Mapped: {user.Name}");
    }
}

Nested Objects

public class OrderDto
{
    public int Id { get; set; }
    public CustomerDto Customer { get; set; }
    public List<OrderItemDto> Items { get; set; }
}

public class OrderEntity
{
    public int Id { get; set; }
    public CustomerEntity Customer { get; set; }
    public List<OrderItemEntity> Items { get; set; }
}

// OnMapper automatically maps nested objects and collections
var orderDto = new OrderDto { /* ... */ };
var result = await mapper.Map<OrderDto, OrderEntity>(orderDto);

🎯 Usage Patterns

Dependency Injection

// In Program.cs or Startup.cs
services.AddScoped<IMappingService, OnMapping>();

// In your service or controller
public class UserService
{
    private readonly IMappingService _mapper;
    
    public UserService(IMappingService mapper)
    {
        _mapper = mapper;
    }
    
    public async Task<UserDto> GetUserAsync(int id)
    {
        var userEntity = await _repository.GetByIdAsync(id);
        var result = await _mapper.Map<UserEntity, UserDto>(userEntity);
        return result.Data;
    }
}

Error Handling

var result = await mapper.Map<SourceType, DestinationType>(source);

if (result.IsSuccess)
{
    // Success - use result.Data
    var mapped = result.Data;
}
else
{
    // Failure - handle error
    Console.WriteLine($"Mapping failed: {result.Message}");
}

🔧 Advanced Features

Result Pattern

OnMapper uses a Result pattern for robust error handling:

public class Result<T>
{
    public bool IsSuccess { get; set; }
    public string Message { get; set; }
    public T Data { get; set; }
}

Property Matching

OnMapper matches properties by name. Properties must:

  • Have the same name in source and destination
  • Be readable in source
  • Be writable in destination

📊 Performance Tips

  1. Reuse Mapper Instance - Create one instance and reuse it (singleton or scoped)
  2. Avoid Unnecessary Mappings - Only map when crossing boundaries (e.g., API layer)
  3. Use Collections Wisely - For large collections, consider pagination

🆚 Comparison with AutoMapper

Feature OnMapper AutoMapper
Configuration Zero config Requires profiles
Performance Lightweight Feature-rich but heavier
Learning Curve Minimal Moderate
Async Support Built-in Built-in
Use Case Simple mappings Complex scenarios

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

👥 Authors

  • Moath Al-Makhlafi
  • Osama Dammag

🙏 Acknowledgments

Created to simplify object mapping in .NET applications with minimal overhead and maximum developer productivity.

📞 Support

If you encounter any issues or have questions:

  • Open an issue on GitHub
  • Check existing documentation
  • Review the examples above

Made with ❤️ for the .NET community

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

    • No dependencies.
  • net7.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 89 2/2/2026
1.1.9 203 5/30/2024

Version 2.0.0:
     - Multi-targeting support for .NET 6, 7, and 8
     - Performance improvements with reflection caching
     - Enhanced error handling and validation
     - Fixed typo: FaildAsync renamed to FailedAsync
     - Added comprehensive XML documentation
     - Improved nullable reference type support
     - Added support for modern C# features