Where to place AutoMapper map registration in referenced dll

前端 未结 2 1328
终归单人心
终归单人心 2021-01-14 22:29

This is my first AutoMapper project and may be obvious to some but the tutorials and examples are not clicking with me. I am trying to understand where and to a certain degr

2条回答
  •  迷失自我
    2021-01-14 23:10

    Put it in the static constructor of either the source or the target type of the mapping.

    public class FullData
    {
        static FullData()
        {
    
            Mapper.CreateMap, FullData>()
                .ForMember(d => d.Acres, m => m.ResolveUsing(new RawLeadDataNameResolver("Acres")));
        }
     }
    

    The static constructor will automatically get called the first time you try to use the type FullData for anything (for example a mapping).

提交回复
热议问题