AIMapper 1.0.0
dotnet add package AIMapper --version 1.0.0
NuGet\Install-Package AIMapper -Version 1.0.0
<PackageReference Include="AIMapper" Version="1.0.0" />
<PackageVersion Include="AIMapper" Version="1.0.0" />
<PackageReference Include="AIMapper" />
paket add AIMapper --version 1.0.0
#r "nuget: AIMapper, 1.0.0"
#:package AIMapper@1.0.0
#addin nuget:?package=AIMapper&version=1.0.0
#tool nuget:?package=AIMapper&version=1.0.0
AIMapper
Fleksibel, intuitif, dan performa tinggi untuk object mapping di .NET
✨ Tentang AIMapper
AIMapper adalah library object-to-object mapping untuk .NET 8 yang mendukung konfigurasi berbasis atribut maupun fluent interface.
Dirancang sebagai alternatif ringan AutoMapper, AIMapper mendukung:
- Flattening & unflattening properti nested
- Mapping berbasis atribut
[Map]
- Konfigurasi fluent (
cfg.ForMember(...)
) - Null substitute, converter, condition, ignore
- Paging async dan collection projection
- ReverseMap dan mapping profile terpusat
- Tanpa konfigurasi runtime
📦 Instalasi
dotnet add package AIMapper
🚀 Quick Start
1. Definisikan Model & DTO
public class User {
public int Id { get; set; }
public string? Name { get; set; }
public UserProfile? Profile { get; set; }
}
public class UserProfile {
public string? Address { get; set; }
}
public class UserDto {
public int Id { get; set; }
public string? Name { get; set; }
public string? Address { get; set; }
}
2. Tambahkan ke DI
services.AddAIMapper();
3. Konfigurasi Mapping
mapper.Configure<User, UserDto>(cfg => {
cfg.ForMember("Address", o => o.CustomPath = "Profile.Address");
});
4. Mapping Object & Koleksi
var dto = mapper.Map<User, UserDto>(user);
var dtos = users.ProjectTo<User, UserDto>(mapper).ToList();
🎯 Fitur Fluent Mapping
Fitur | Contoh |
---|---|
Ignore | cfg.ForMember("Name", o => o.Ignore()); |
CustomPath | cfg.ForMember("Address", o => o.CustomPath = "Profile.Address"); |
Condition | cfg.ForMember("IsActive", o => o.Condition<User, UserDto>((src, dest) => src.Status == StatusEnum.Active)); |
NullSubstitute | cfg.ForMember("Email", o => o.NullSubstitute("default@email.com")); |
ValueConverter | cfg.ForMember("Registered", o => o.ConvertUsing<DateTime?, string?>(dt => dt?.ToString("yyyy-MM-dd"))); |
BeforeMap / AfterMap | cfg.BeforeMap(...); cfg.AfterMap(...); |
ReverseMap | cfg.ReverseMap((Mapper)mapper); |
Paging Async | var pageDto = await users.ProjectToPagedListAsync<User, UserDto>(mapper, 1, 10); |
🔥 Contoh MappingProfile
public class UserProfileMap : MapperProfile
{
public override void Configure(IMapper mapper)
{
mapper.Configure<User, UserDto>(cfg =>
{
cfg.ForMember("Address", o => o.CustomPath = "Profile.Address");
cfg.ForMember("Email", o => o.NullSubstitute("default@email.com"));
cfg.ForMember("Registered", o => o.ConvertUsing<DateTime?, string?>(dt => dt?.ToString("yyyy-MM-dd")));
cfg.ForMember("IsActive", o => o.Condition<User, UserDto>((src, dest) => src.Status == StatusEnum.Active));
cfg.ForMember("Name", o => o.Ignore());
cfg.BeforeMap((src, dest) => dest.Point = src.Point ?? 0);
cfg.AfterMap((src, dest) => dest.Name = src.Name?.ToUpper());
cfg.ReverseMap((Mapper)mapper);
});
mapper.Configure<Order, OrderDto>(cfg =>
{
cfg.ForMember("CustomerName", o => o.CustomPath = "Customer.Name");
cfg.ForMember("Total", o => o.NullSubstitute(0));
cfg.AfterMap((src, dest) => dest.IsPaid = src.Status == OrderStatus.Paid);
cfg.ReverseMap((Mapper)mapper);
});
}
}
Registrasi MappingProfile:
mapper.ApplyProfilesFromCurrentAssembly();
📁 Contoh Lengkap
Lihat AIMapperSampleDemo.cs
di project AIMapper.SampleApp untuk contoh implementasi penuh.
📄 Lisensi
Proyek ini menggunakan lisensi MIT License.
Product | Versions 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 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. |
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.4)
- Microsoft.Extensions.DependencyInjection (>= 8.0.0)
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 |
---|---|---|
1.0.0 | 364 | 7/25/2025 |
Versi 1.0.0 AIMapper:
- Support untuk mapping berbasis atribut
- Flattening dan unflattening property kompleks
- NullSubstitute, Condition, dan Converter berbasis MapAttribute
- Nama class dan interface konsisten dengan AutoMapper