We used ModelBinders.Binders
on our project to make resolving of controller action parameters easier and make code more testable.
ModelBinders.Binders[typeof(SomeType)] = new SomeTypeModelBinder();
Model binder resolves object:
public class SomeTypeModelBinder : IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var someTypeResolver = DependencyResolver.Current.GetService<ISomeTypeResolver>();
return someTypeResolver.GetCurrentSomeType();
}
}
Then it becomes easy to use this type as model in our controllers:
public ActionResult SomeAction(SomeType someType)
{
return View(someType);
}
The problem is that it becomes hard to measure performance of action using Sitecore Debug. It looks like binding of action parameter in this way causes that it is not summed up to time of rendering controller action(this assumptions is done, because time of rendering is too small):
Finished rendering "Controller: SomeController. Action: SomeAction". 26.62 ms
The questions are:
- Does Sitecore Debug mode take into account time that is spent on execution of model binders?
- If not, then how to force Sitecore Debug mode to start add this time to total time of execution(and remain code testable)?