Automapper says Mapper.Map is obsolete, global mappings?

后端 未结 5 1214
孤街浪徒
孤街浪徒 2020-12-12 21:01

I had defined in my project a global Automapper configuration that would allow me to use Mapper.Map(sourceObject); in my code. (See my configu

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-12 21:34

    This is new in AutoMapper 4.2. There is a blog post by Jimmy Bogard on this: Removing the static API from AutoMapper. It claims that

    The IMapper interface is a lot lighter, and the underlying type is now just concerned with executing maps, removing a lot of the threading problems...

    The new syntax: (pasted from the blog post)

    var config = new MapperConfiguration(cfg => {
      cfg.CreateMap();
    });
    

    If you just want the "old way" of doing this. The latest version 4.2.1 has brought back some tradition. Just use

    CreateMap();
    

    instead of

    Mapper.CreateMap();
    

    The old code will work just fine.

提交回复
热议问题