Skip to content

Instantly share code, notes, and snippets.

@lucasselliach
Last active October 5, 2015 11:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucasselliach/146617fdc99af188584c to your computer and use it in GitHub Desktop.
Save lucasselliach/146617fdc99af188584c to your computer and use it in GitHub Desktop.
AutoMapper
public class AutoMapperConfig
{
public static void RegisterMappings()
{
Mapper.Initialize(c =>
{
c.AddProfile<DomainToViewModelMappingProfile>();
c.AddProfile<ViewModelToDomainMappingProfile>();
});
}
}
public class DomainToViewModelMappingProfile : Profile
{
public override string ProfileName
{
get { return "ViewModelToDomainMappings"; }
}
protected override void Configure()
{
Mapper.CreateMap<UserViewModel, User>();
}
}
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AutoMapperConfig.RegisterMappings();
}
}
public class ViewModelToDomainMappingProfile : Profile
{
public override string ProfileName
{
get { return "DomainToViewModelMappings"; }
}
protected override void Configure()
{
Mapper.CreateMap<User, UserViewModel>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment