public class MasterViewModel : IMasterViewModel
{
public string SiteName { get; set; }
}
I was able to take care of the second concern by simply creating a base controller that all of my controllers would inherit from and then override View(string viewName, string masterName, object model) { … } so that the settings are automatically injected into the model.
protected override ViewResult View(string viewName, string masterName, object model)
{
((MasterViewModel)model).SiteName = "Example";
return base.View(viewName, masterName, model);
}
In order to get around the smell of forcing my ViewModel’s to inherit from a base class I put the MasterViewModel into the ViewData dictionary that is returned in the ViewResult.
protected override ViewResult View(string viewName, string masterName, object model)
{
ViewResult result = base.View(viewName, masterName, model);
result.ViewData[Data.Site] = _blogConfiguration.Configuration;
return result;
}
Read more: about:thoughts