I have this template
public abstract class BaseController : Controller { readonly RepositoryFactory _rep; protected RepositoryFactory rep { get { return _rep; } } readonly ManageRoles _man; readonly ElementAvailableForUser _env; protected ElementAvailableForUser env { get { return _env; } } public BaseController() : this(DependencyResolver.Current.GetService<RepositoryFactory>(), DependencyResolver.Current.GetService<ManageRoles>(), DependencyResolver.Current.GetService<ElementAvailableForUser>()) { } public BaseController(RepositoryFactory rep, ManageRoles man, ElementAvailableForUser env) { _rep = rep; _man = man; _env = env; } }
so i can do something like this
public class HomeController : BaseController { public ActionResult Index() { return View(rep.Offers.GetAll()); } public ActionResult Sections() { return View(env); } }
all over my controller. I am sure that it is antipattern for DI and IoC, so I thin this solution
public abstract class BaseController : Controller { ...
but this solution requires me to insert all the dependencies into all the controllers and update all the constructors if I need a new global variable (e.g. rep) or a new private variable for the base controller (e.g. man).
Which template should I follow and why?
Edit I found this question and this one , but still I cannot figure out which design patterns I should follow.
source share