AU

AutoMapper

Object-to-object mapping

Details

Language / Topic
csharpC#
Category
Libraries

Rules

balanced
- Define mapping profiles in `Profile` subclasses using `CreateMap<TSource, TDest>()` — register all profiles via `AddAutoMapper(assembly)` in DI.
- Use `ForMember()` for custom property mappings — avoid implicit mappings for non-trivial transformations that hide business logic.
- Call `AssertConfigurationIsValid()` in tests to catch missing property mappings at test time, not at runtime.
- Create one profile per domain area. Use `CreateMap<TSource, TDest>()` with explicit member configuration.
- Use `ForMember()` for custom mappings, `.Ignore()` for excluded properties.
- Use `ProjectTo<TDest>()` on IQueryable for efficient database projections without loading full entities.
- Validate all mappings at startup with `mapper.ConfigurationProvider.AssertConfigurationIsValid()`.