I'm creating WCF services that return data contract types by mapping Entity Framework types. What is the best place to put the Mapper.CreateM开发者_运维百科ap calls? Should I do it in each service and only for that service, or should I do it on service startup?
Thoughts?
I think you can create it once and cache in static field:
private static MapClass _MapInstance;
public static MapClass Map
{
get
{
if(_MapInstance == null)
_MapInstance = Mapper.CreateMap();
return _MapInstance;
}
}
Also as far as I know creating mapper is performance-expencive operation, because it may use code generation, sou you shouldn't do it on each call.
精彩评论