Overview
Convention over Configuration
AutoMapper does have Auto in its name. If we follow closely Conventions, we rarely need MappingConfiguration.
As we have already seen in previous examples, matching properties are mapped automatically as long as the metadata is provided.
class User {
    @AutoMap()
    firstName!: string;
    @AutoMap()
    lastName!: string;
}
class UserDto {
    @AutoMap()
    firstName!: string;
    @AutoMap()
    lastName!: string;
}
Nested models are also auto-mapped.
class Address {
    @AutoMap()
    street!: string;
}
class Bio {
    @AutoMap()
    text!: string;
    @AutoMap(() => [Address])
    addresses: Address[] = [];
}
class User {
    @AutoMap(() => Bio)
    bio!: Bio;
}
class AddressDto {
    @AutoMap()
    street!: string;
}
class BioDto {
    @AutoMap()
    text!: string;
    @AutoMap(() => [AddressDto])
    addresses: AddressDto[] = [];
}
class UserDto {
    @AutoMap(() => BioDto)
    bio!: BioDto;
}
In addition, there is Auto Flattening. These features should encourage us to stay as close to the conventions as possible.
Custom Configuration
MappingConfiguration are functions that augment a Mapping. When creating a Mapping with createMap(), we can pass in as many MappingConfiguration as we like and in any order that we want.
| mapping configuration | description | 
|---|---|
| afterMap() | Attach a MapCallbackto run after the map operation | 
| beforeMap() | Attach a MapCallbackto run before the map operation | 
| constructUsing() | Set a custom constructor for the Destinationbefore the map operation | 
| extend() | Extend another Mapping | 
| forMember() | Configure a MappingTransformationfor a property on theDestination | 
| forSelf() | Configure flattening for Destinationfrom a differentSource | 
| namingConventions() | Configure the NamingConventionfor thisMapping | 
| typeConverters() | Configure the TypeConverterfor thisMapping | 
caution
If the Mapping have an absurd amount of custom MappingConfiguration, it's time to re-evaluate the models or if AutoMapper is the right tool for the project.