MiniMapr

Welcome to MiniMapr

NuGet License: MIT

MiniMapr is a lightweight, high-performance object-to-object mapper for .NET applications.

It was designed to offer developers a clean and minimal API to define custom mapping rules without the complexity or overhead of traditional mappers. Whether you’re working on a Web API, a background service, or a desktop app, MiniMapr provides a fast and extensible mapping solution.


πŸš€ Features


πŸ“¦ Install MiniMapr

You can get started by installing MiniMapr via NuGet:

dotnet add package MiniMapr

Getting Started

Instalation

Install MiniMapr via NuGet:

dotnet add package MiniMapr

Defining Source and Target Classes

Let’s assume you have a domain model and a DTO:

public class User
{
    public string Name { get; set; }
    public string Email { get; set; }
    public string Password { get; set; }
    public Address Address { get; set; }
}

public class UserDto
{
    public string Name { get; set; }
    public string EmailAddress { get; set; }
    public string Password { get; set; } = "";
    public AddressDto Address { get; set; }
}

public class Address
{
    public string Street { get; set; }
}

public class AddressDto
{
    public string Street { get; set; }
}

Creating Mapping Configuration Classes

To define how mapping should occur, implement IMapperConfig:

Example:

using MiniMapr;

public class UserMappingConfig : IMapperConfig 
{ 
    public void Configure(MapperService mapper) 
    { 
        mapper.Add<User, UserDto>(config => 
        { 
            config.IgnoredProperties.Add("Password"); 
            config.CustomMappings["Email"] = "EmailAddress"; 
            config.AddCustomTransformation<Address, AddressDto>("Address", address =>
                mapper.Map<Address, AddressDto>(address));
        });
    }
}

public class AddressMappingConfig : IMapperConfig 
{ 
    public void Configure(MapperService mapper) 
    { 
        mapper.Add<Address, AddressDto>(); 
    } 
}

Registering MiniMapr

To enable MiniMapr in your application, register your mapping configurations:

var services = new ServiceCollection();

services.AddMapper(mapper => 
{ 
    mapper.Add<UserMappingConfig>()
        .Add<AddressMappingConfig>();
});

var serviceProvider = services.BuildServiceProvider();
var mapperService = serviceProvider.GetRequiredService<IMapper>();

Performing a Mapping

Once registered, you can use the mapper as follows:

var user = new User
{
    Name = "Alice",
    Email = "alice@email.com",
    Password = "secret123",
    Address = new Address { Street = "123 Maple St" }
};

var userDto = mapperService.Map<User, UserDto>(user);

Console.WriteLine(userDto.Name); // Alice
Console.WriteLine(userDto.EmailAddress); // alice@email.com
Console.WriteLine(userDto.Password); // (empty)
Console.WriteLine(userDto.Address.Street); // 123 Maple St

πŸ“š Documentation


πŸ§‘β€πŸ’» Contributing

We welcome contributions of all kinds β€” whether you’re fixing bugs, adding features, writing documentation, or suggesting improvements.

To get started:

  1. Fork the repository
  2. Create a feature branch
  3. Submit a pull request

πŸ“ƒ License

This project is licensed under the MIT License. You are free to use, modify, and distribute it as needed.


If you find MiniMapr useful, consider starring the repository ⭐ to support the project!