I set up a project a while back, as follows, A class named AutoMapperConfig as follows:
public class AutoMapperConfig
{
public static void RegisterMappings()
{
Mapper.Initialize(x =>
{
x.AddProfile<DomainToViewModelMappingProfile>();
x.AddProfile<ViewModelToDomainMappingProfile>();
});
}
}
Another class: DomainToViewModelMappingProfile that maps Domain to ViewModel:
public class DomainToViewModelMappingProfile : Profile
{
public override string ProfileName
{
get { return "ViewModelToDomainMappings"; }
}
protected override void Configure()
{
Mapper.CreateMap<UsuarioViewModel, Usuario>();
}
}
and one that maps from ViewModel to the Domain:
public class ViewModelToDomainMappingProfile : Profile
{
public override string ProfileName
{
get { return "DomainToViewModelMappings"; }
}
protected override void Configure()
{
Mapper.CreateMap<Usuario, UsuarioViewModel>();
}
}
And Controller Where I call a method where I get all users saved in the database
public ActionResult Index()
{
var UsuarioViewModel= Mapper.Map<IEnumerable<Usuario>, IEnumerable<UsuarioViewModel>>(_usuarioApp.ObterTodos());
return View(UsuarioViewModel);
}
And lastly in Global.asax call AutoMapperConfig.RegisterMappings ();
This already worked perfectly the mapping for this context ... But I have seen that from version 4.2 of AutoMapper this type of configuration is obsolete. How do I implement the new form framework?