0

28.2 ForAllMaps, ForAllPropertyMaps, Advanced and other “missing” APIs

Some APIs were hidden for normal usage. To light them up, you need to add an using for AutoMapper. Internal and call the Internal extension method on the configuration object. Most users don’t need these advanced methods. Some expose internals and are not subject to the usual semantic versioning rules. To avoid such tight coupling to AutoMapper, you should try to stick to the public API.

I have ForAllMapps call in the project (NopCommerce 4.50.1). The original project uses AutoMapper 8.1.1. I want to update it to the newest package (11). What can I use instead (with example if possible).

Thank you.

Alex Kudryashev
  • 9,120
  • 3
  • 27
  • 36

2 Answers2

2

For AutoMap 11, Some APIs were hidden for normal usage. To light them up, you need to add an using for AutoMapper.Internal and call the Internal extension method on the configuration object. Most users don’t need these advanced methods. Some expose internals and are not subject to the usual semantic versioning rules. To avoid such tight coupling to AutoMapper, you should try to stick to the public API.

ForAllMaps, ForAllPropertyMaps, Advanced and other “missing” APIs, use the API instead:

void ConfigurationExpression(IMapperConfigurationExpression cfg)
{
    AutoMapper.Internal.InternalApi.Internal(cfg).ForAllMaps(MappingExpression);
}

https://docs.automapper.org/en/latest/11.0-Upgrade-Guide.html#forallmaps-forallpropertymaps-advanced-and-other-missing-apis

https://github.com/AutoMapper/AutoMapper/blob/9f2f16067ab201a5a8b9bc982f3a37e8790da7a0/src/AutoMapper/Internal/InternalApi.cs#L15

shine
  • 610
  • 3
  • 10
0

If they consider ForAllMaps to be too tightly coupled, you could write your own implementation:

public class AutoMapperConfig : Profile
{
    public AutoMapperConfig()
    {
        this.CreateCustomMap<Model1, Model2>() 
    }
}

public static class ProfileExtensions
{
    public static IMappingExpression<TFrom, TTo> CreateCustomMap<TFrom, TTo>(this Profile profile)
    {
        var mappingExpression = profile.CreateMap<TFrom, TTo>();

        // do something like mappingExpression.ForMember(...)

        return mappingExpression;
    }
}