Automapper error saying mapper not initialized

后端 未结 3 1633
执笔经年
执笔经年 2020-12-08 16:17

I am using Automapper 5.2. I have used as a basis this link. I will describe, in steps, the process of setting up Automapper that I went through.

First

3条回答
  •  悲&欢浪女
    2020-12-08 16:25

    Better Solution would be to create extension method like this

      public static DestinationType CastObject(this SourceType obj)
                {
                    var config = new MapperConfiguration(cfg =>
                    cfg.CreateMap());
    
                    var mapper = config.CreateMapper();
    
                    var entity = mapper.Map(obj);
    
                    return entity;
                }
    

提交回复
热议问题