Azka.ObjectMapper
10.0.0-alpha6
See the version list below for details.
dotnet add package Azka.ObjectMapper --version 10.0.0-alpha6
NuGet\Install-Package Azka.ObjectMapper -Version 10.0.0-alpha6
<PackageReference Include="Azka.ObjectMapper" Version="10.0.0-alpha6" />
<PackageVersion Include="Azka.ObjectMapper" Version="10.0.0-alpha6" />
<PackageReference Include="Azka.ObjectMapper" />
paket add Azka.ObjectMapper --version 10.0.0-alpha6
#r "nuget: Azka.ObjectMapper, 10.0.0-alpha6"
#:package Azka.ObjectMapper@10.0.0-alpha6
#addin nuget:?package=Azka.ObjectMapper&version=10.0.0-alpha6&prerelease
#tool nuget:?package=Azka.ObjectMapper&version=10.0.0-alpha6&prerelease
Azka.ObjectMapper
Azka.ObjectMapper is a lightweight object mapping library for .NET, designed to map data between classes (for example, Entity to DTO) using profile-based configuration.
Features
- Object mapping
TSource -> TDestination. - Collection mapping
IEnumerable<TSource> -> IEnumerable<TDestination>. - Mapping into an existing destination instance.
- Custom member mapping with
ForMember(...). - Ignore source members with
Ignore(...). - Nested object mapping support (when profiles exist).
- Nested collection mapping support.
- Simple type conversion support for primitives, nullable values, and enums.
- Mutable read-only collection population support.
- Integration with
Microsoft.Extensions.DependencyInjection.
Installation
dotnet add package Azka.ObjectMapper
Quick Start
1. Create models
public class User
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public DateTime CreatedAt { get; set; }
}
public class UserDto
{
public Guid Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Email { get; set; } = string.Empty;
public long CreatedAtUnix { get; set; }
}
2. Create a mapping profile
using Azka.ObjectMapper;
public class UserMapProfile : ObjectMapProfile
{
public UserMapProfile()
{
CreateMap<User, UserDto>()
.ForMember(dest => dest.CreatedAtUnix, src =>
new DateTimeOffset(src.CreatedAt).ToUnixTimeSeconds());
}
}
3. Register in DI
Option A - register a profile instance:
using Azka.ObjectMapper;
builder.Services.AddObjectMapper(new UserMapProfile());
Option B - scan profiles from assembly:
using System.Reflection;
using Azka.ObjectMapper;
builder.Services.AddObjectMapper(Assembly.GetExecutingAssembly());
Option C - scan profiles from multiple assemblies:
using System.Reflection;
using Azka.ObjectMapper;
builder.Services.AddObjectMapper(new List<Assembly>
{
Assembly.GetExecutingAssembly(),
typeof(SharedMapProfile).Assembly
});
Option D - use without DI:
using Azka.ObjectMapper;
IObjectMapper mapper = new DefaultObjectMapper(new UserMapProfile());
4. Use in service/controller
using Azka.ObjectMapper;
public class UsersService
{
private readonly IObjectMapper _mapper;
public UsersService(IObjectMapper mapper)
{
_mapper = mapper;
}
public UserDto GetDto(User user)
{
return _mapper.Map<User, UserDto>(user);
}
public IEnumerable<UserDto> GetDtos(IEnumerable<User> users)
{
return _mapper.Map<User, UserDto>(users);
}
public UserDto UpdateDto(User user, UserDto dto)
{
return _mapper.Map<User, UserDto>(user, dto);
}
}
Mapping Configuration
ForMember (custom destination member)
CreateMap<User, UserDto>()
.ForMember(dest => dest.Name, src => $"[USER] {src.Name}");
Ignore (ignore source member)
CreateMap<User, UserDto>()
.Ignore(src => src.Email);
Type conversion
When source and destination property names match, the mapper attempts compatible simple conversions such as string to int, numeric values to enums, enum names from strings, and nullable destination values.
public class User
{
public string Age { get; set; } = "20";
public string Status { get; set; } = "Active";
}
public class UserDto
{
public int Age { get; set; }
public UserStatus Status { get; set; }
}
public enum UserStatus
{
Active,
Inactive
}
Nested Mapping
If a property is a complex object or a collection of complex objects, profiles for child types must also be available.
public class Address
{
public string City { get; set; } = string.Empty;
}
public class AddressDto
{
public string City { get; set; } = string.Empty;
}
public class User
{
public Address Address { get; set; } = new();
}
public class UserDto
{
public AddressDto Address { get; set; } = new();
}
public class UserMapProfile : ObjectMapProfile
{
public UserMapProfile()
{
CreateMap<Address, AddressDto>();
CreateMap<User, UserDto>();
}
}
Collection Mapping
Collections are mapped by element type. Primitive collections can be converted when the element values are compatible, and complex object collections require child profiles.
public class User
{
public string[] Tags { get; set; } = [];
}
public class UserDto
{
public List<string> Tags { get; set; } = [];
}
Collection values are created internally as List<TDestinationElement>. This works well for destination properties typed as List<T>, IEnumerable<T>, ICollection<T>, or other compatible assignable collection abstractions. Destination array properties such as string[] are not converted from that internal list automatically.
For destination properties without a public setter, the mapper can populate the existing collection when it is mutable, such as a List<T> exposed through a read-only property.
public class UserDto
{
public List<string> Tags { get; } = [];
}
When populating an existing mutable collection, the mapper clears the current collection and adds the mapped items.
API Summary
IObjectMapper.Map<T, U>(T obj)maps a single object to destination type.IObjectMapper.Map<T, U>(IEnumerable<T> listOfObjects)maps an object collection to destination collection type.IObjectMapper.Map<T, U>(T source, U target)maps source values into an existing destination instance and returns that same destination instance.MapProfile<T, U>.ForMember(...)defines custom mapping for a destination member.MapProfile<T, U>.Ignore(...)ignores a source member.IServiceCollection.AddObjectMapper(ObjectMapProfile profile)registers a mapper from a profile instance.IServiceCollection.AddObjectMapper(Assembly assembly)scans public profile classes from an assembly.IServiceCollection.AddObjectMapper(List<Assembly> assemblies)scans public profile classes from multiple assemblies.DefaultObjectMapper(ObjectMapProfile profile)creates a mapper directly from one profile without DI.DefaultObjectMapper(IEnumerable<ObjectMapProfile> profiles)creates a mapper directly from multiple profiles without DI.
Important Notes
- Mapping to a new destination instance requires the destination type to have a public parameterless constructor.
- Mapping into an existing destination instance does not create a new destination instance, so the destination type itself does not need a parameterless constructor for that API.
- Mapping into an existing destination instance requires both
sourceandtargetarguments to be non-null. - Mapping only works when a
CreateMap<T, U>()profile exists. - For nested types, nested profiles are also required.
- Nested destination types that must be created by the mapper require a public parameterless constructor.
- Collection item destination types that must be created by the mapper require a public parameterless constructor.
- If a mapping profile is not found, mapper throws
InvalidOperationException. - If source is null when mapping to a new destination, mapper returns default.
- If source is null when mapping into an existing destination instance, mapper throws
ArgumentException. - If a non-custom property value cannot be converted to the destination property type, that property is skipped.
- If a custom
ForMember(...)value cannot be converted to the destination property type, mapper throwsInvalidOperationException. - Assembly scanning only registers public, non-abstract
ObjectMapProfileclasses with a parameterless constructor. - Assembly scanning includes public nested profile classes and ignores
ObjectMapProfileCollections. - Combining multiple profiles with the same source and destination pair throws
DuplicateWaitObjectException.
Requirements
- .NET 10.0 or later
- Microsoft.Extensions.DependencyInjection 10.0.2 or later
License
See LICENSE.txt.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.2)
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 |
|---|---|---|
| 10.0.0-rc.4 | 50 | 11/9/2026 |
| 10.0.0-rc.3 | 70 | 11/7/2026 |
| 10.0.0-rc.2 | 67 | 10/27/2026 |
| 10.0.0-rc.1 | 116 | 6/30/2026 |
| 10.0.0-alpha6 | 92 | 6/20/2026 |
| 10.0.0-alpha5 | 102 | 3/16/2026 |
| 10.0.0-alpha.9 | 91 | 6/25/2026 |
| 10.0.0-alpha.8 | 90 | 6/25/2026 |
| 10.0.0-alpha.7 | 99 | 6/25/2026 |
Initial release of Azka.ObjectMapper
- Object Mapper