Skip to main content

Posts

Showing posts from February, 2016

Migrating old AutoMapper codes to 4.2 version with instance based approach

In AutoMapper 4.2 version, static implementation is removed with instance approach. It could be a nightmare to migrate the codes to the newer version with instance approach. I will be putting up guide for migrating codes from the older version to instance approach if someone has used Profile based approach. Previous implementation (old implementation) Profile based implementation mapping public class UserProfileMapping : Profile { protected override void Configure() { Mapper.CreateMap<UserProfile, PreferenceViewModel>() .ForMember(vm => vm.UserId, m => m.MapFrom(profile => profile.Id)); } } Single class for registering all AutoMapper configuration public static class AutoMapperConfiguration { public static void Configure() { Mapper.Initialize(cfg => { cfg.AddProfile(new UserProfileMapping()); }); } }