I was thinking of sending Phil an email with this suggestion.. but as it hasn't been looked over from all angles (didn't use it in real code... just thinking out loud because of some testability issues I am having) didn't do it and had an idea to post it here to see what others think.
Ok... first to say that currently it's written as inherited from the default Controller, but my suggestion would actually be that this IS how the default controller looks (or better said, take a look at the bits and imagine that the rest of the Controller code is there :) and that this is not an inherited implementation of Controller, but rather the Controller itself)
A trully generic controller:
public class TestableController<TViewData, TTempData> : Controller {
public string ViewName
{
get
{
return _viewName;
}
}
private string _viewName;
public string MasterName
{
get
{
return _masterName;
}
}
private string _masterName;
public TViewData ViewData {
get {
return _viewData;
}
}
private TViewData _viewData;
public TTempData TempData
{
get
{
return _tempData;
}
}
private TTempData _tempData;
public virtual void RenderView(string viewName)
{
_viewName = viewName;
base.RenderView(viewName);
}
public virtual void RenderView(string viewName, TViewData viewData)
{
_viewName = viewName;
_viewData = viewData;
base.RenderView(viewName, viewData);
}
public virtual void RenderView(string viewName, string masterName, TViewData viewData)
{
_viewName = viewName;
_masterName = masterName;
_viewData = viewData;
base.RenderView(viewName, masterName, viewData);
}
}
And the default generics-less implementation (to support the dictionary scenario which you can use now which is ok):
public class TestableController : TestableController<Dictionary<string, object>, Dictionary<string, object>>
{
}
What do you think, is this worthwhile suggesting or?