'AutoMapper 11. Missing API replacements

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.



Solution 1:[1]

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;
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jeff Fichtner