我目前有一个RegisterMaps
从Application_Start
.
public static class AutoMapperRegistrar
{
public static void RegisterMaps()
{
Mapper.CreateMap<Employee, EmployeeEditModel>();
Mapper.CreateMap<Employee, EmployeeCreateModel>();
}
}
我还有一个MappedViewModel
基类,我的大多数视图模型都派生自:
public class MappedViewModel<TEntity>: ViewModel
{
public virtual void MapFromEntity(TEntity entity)
{
Mapper.Map(entity, this, typeof(TEntity), GetType());
}
}
现在维护一长串映射RegisterMaps
对我来说有点麻烦。我正在考虑将地图创建委托给MappedViewModel
. 我可以安全地做到这一点,即它会对性能产生负面影响,还是有任何其他理由不做更多的面向对象并让每个映射类创建自己的映射?