In my MVC4, .NET4.5 web app using Unity IoC container, in the method IoCContainerFactory.GetControllerInstance() we use ServiceLocator.Current.GetInstance to get the controller instance:
public class IoCControllerFactory : DefaultControllerFactory
{
protected override IController GetControllerInstance(
System.Web.Routing.RequestContext requestContext, Type controllerType)
{
// snip other code
// this is the problem line:
return ServiceLocator.Current.GetInstance(controllerType) as IController;
}
}
But this has been performing too slowly. Using JetBrains DotNetTrace product I've found that ServiceLocator.Current.GetInstance appears to be calling ObjectBuilder2.PolicyList.GetNoDefault more than one million times. How can I figure out why it is making so many calls, and what can I do to fix this problem? Attached screenshot shows the output from dotnetTrace:
And what policy is it trying to get in the method PolicyList.GetNoDefault
? I I knew what policy it was trying to find I could perhaps change that policy so that it does need to be checked so many times.