Sometimes, I need to map from a Domain entity to a ViewModel - to display information.
Other times, I need to map from a ViewModel to a Domain entity - for persistance of data.
Is this kosher or does this code smell?
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
MapObjects();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
private void MapObjects()
{
Mapper.CreateMap<UserModel, User>();
Mapper.CreateMap<ProductBrandModel, ProductBrand>();
Mapper.CreateMap<ProductBrand, ProductBrandModel>();
Mapper.CreateMap<ProductCategoryModel, ProductCategory>();
Mapper.CreateMap<ProductCategory, ProductCategoryModel>();
}
ProductBrandModel
andProductBrand
on a whiteboard showing their relationships, then see if you can't turn make the relationships one way by breaking either of them up such that no two-way relationship exists between any of the classes on the whiteboard. \$\endgroup\$