Abp object mapping

From burakdmir/abp-skills · View interactive version

Abp object mapping is an AI agent skill from the GitHub repository burakdmir/abp-skills. ABP Framework v10.x (10.4–10.6) object mapping quick reference: IObjectMapper, Mapperly (default since v10.4), AutoMapper profile/attribute, entity↔DTO. Use when you need object mapping in ABP.

How to use this skill

Skill file

ABP Framework — Object Mapping

ABP v10.x object mapping. The IObjectMapper abstraction; Mapperly is the default (compile-time), AutoMapper is also supported.

Trigger

"ABP object mapping", "DTO mapping", "Mapperly", "AutoMapper", "IObjectMapper".

Usage (ObjectMapper)

ObjectMapper.Map<Book, BookDto>(book);
ObjectMapper.Map<List<Book>, List<BookDto>>(books);
ObjectMapper.Map(input, book);    // onto an existing destination

ObjectMapper is available in base classes; elsewhere, inject IObjectMapper.

Mapperly (default)

[Mapper]
public partial class BookMapper : MapperBase<Book, BookDto>
{
    public override partial BookDto Map(Book source);
    public override partial void Map(Book source, BookDto destination);
}
// Module: [DependsOn(typeof(AbpMapperlyModule))] + context.Services.AddMapperlyObjectMapper<MyModule>();
// Custom field: [MapProperty(nameof(Book.Name), nameof(BookDto.Title))]

AutoMapper (alternative)

public class MyProfile : Profile
{
    public MyProfile() { CreateMap<Book, BookDto>(); CreateMap<CreateUpdateBookDto, Book>(); }
}
// Module: [DependsOn(typeof(AbpAutoMapperModule))]
// context.Services.AddAutoMapperObjectMapper<MyModule>();
// Configure<AbpAutoMapperOptions>(o => o.AddMaps<MyModule>(validate: true));

// Attribute:
[AutoMapFrom(typeof(Book))] public class BookDto : EntityDto<Guid> { }
[AutoMapTo(typeof(Book))] public class CreateBookDto { }

Best Practices

  1. Use the ObjectMapper abstraction (don't depend on the provider)
  2. Mapperly for new projects (default since v10.4)
  3. Keep mappings in the Application layer; use validate: true with AutoMapper
  4. On create/update, only map allowed fields

Related

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.