Every controller class in my project derive from a base controller class, aptly named BaseController.
All view data is contained in a class named BaseViewData (which in the future could become the base controller for more specific view data classes).
I made a BaseViewData property on the BaseController since every controller requires access to the data inside the strongly-typed base view data (and the BaseController does some work to pre-populate some of the BaseViewData properties).
I did this because:
If I ever changed a property, I would get compile time error checking to resolve broken code more quickly.
Practicing DRY, I've managed to consolidate ALOT of code that was previously scattered throughout each controller.
However, this is the first time I've attempted to do this. So I could be overlooking a problem preparing to rear its ugly head. So:
Is making a BaseViewData class a property of a BaseController class a bad idea? If so, why?
Update 1:
My BaseController looks something like (there's more, but this should get the point across):
public class BaseController
{
public string Language {get; set;}
public string Locale {get; set;}
public BaseViewData Data {get; set;}
protected override void OnActionExecuting(ActionExecutingContext filterContext)
{
var l = (RouteData.Values["language"] != null) ? RouteData.Values["language"].ToString() : "en";
if (l.ToLower().Contains("en"))
{
l = "en";
}
else
l = "ja";
Data.Language = l;
}
}
My BaseViewData looks like this (again, there is more...):
public class BaseViewData
{
public string Language {get;set;}
public string Locale {get;set;}
public bool IsOwner {get;set;}
public string Menu1 {get;set;}
public string Menu2 {get;set;}
public string Menu3 {get;set;}
public IPagedList<TYPE> ListOfTYPE {get;set;}
etc...
}