I currently have a method RegisterMaps
that is called from Application_Start
.
public static class AutoMapperRegistrar
{
public static void RegisterMaps()
{
Mapper.CreateMap<Employee, EmployeeEditModel>();
Mapper.CreateMap<Employee, EmployeeCreateModel>();
}
}
I also have a MappedViewModel
base class that most of my view models derive from:
public class MappedViewModel<TEntity>: ViewModel
{
public virtual void MapFromEntity(TEntity entity)
{
Mapper.Map(entity, this, typeof(TEntity), GetType());
}
}
Now maintaining a long list of mappings in RegisterMaps
creates a bit of friction for me. I am thinking of delegating the map creation to a static constructor in MappedViewModel
. Can I do this safely, i.e. will it negatively affect performance, or is there any other reason to not be more OO and let each mapped class create its own map?