title: Implement controller with arguments in constructor
body: <p>I have alot of not always static values (slogan, banner, description...) and PartialViews (block_head, block_footer, block_right), where i should display it. So, i need to pass big collection of this values into Partial in every Action and it's not very good for me. </p>
  
  <p>I've found interesting solution here: <a href="http://www.asp.net/mvc/tutorials/passing-data-to-view-master-pages-cs" rel="nofollow">http://www.asp.net/mvc/tutorials/passing-data-to-view-master-pages-cs</a> , in part "Good solution". I could move all initialization of this values in ApplicationController and Implement it from my controllers.</p>
  
  <p>But, i'd like to go forward and initialize my Interfaces in ApplicationController too :) If i could do it, i think it should be fantastic. I use Ninject, so, some code:</p>
  
  <pre><code>public abstract class ApplicationController : Controller
  {
      //
      // GET: /Application/
      private readonly IModuleRepository _moduleRepository;
      public IModuleRepository moduleRepository
      {
          get { return _moduleRepository; }
      }
  
      public ApplicationController(IModuleRepository moduleRepository)
      {
          _moduleRepository = moduleRepository;
  
          foreach (var module in _moduleRepository.GetAllModules())
              ViewData[module.name] = module.value;
      }
  }
  </code></pre>
  
  <p>Implementing:</p>
  
  <pre><code>public class HomeController : ApplicationController
  {
      //I can use here moduleRepository without HomeController initialization
  }
  </code></pre>
  
  <p>Just one problem, i don't know how to Implement ApplicationController, if it has arguments. Is it good way and is it any solution for my problem? In future i'm going to set 5-7 Interfaces and have about 10-15 Controllers, so it could be very good to Initialize them all in ApplicationController and Implement in other. Thx, sorry if the questiong is stupid.</p>
  
  <hr>
  
  <p>Ok, adding:</p>
  
  <p>Now, if i have 10 interfaces, it should be like this:</p>
  
  <pre><code>public class HomeController
  {
      private IModuleRepository _moduleRepository;
      private IBookRepository _bookRepository;
      private ITableRepository _tableRepository;
      private IClassRepository _classRepository;
      private IRoomRepository _roomRepository;
      private IUserRepository _userRepository;
      private IWindowRepository _windowRepository;
      private IChairRepository _chairRepository;
      private IDoorRepository _doorRepository;
      private IWCRepository _wcRepository;
  
      public HomeController(IModuleRepository moduleRepository, IBookRepository bookRepository, ITableRepository tableRepository, IClassRepository classRepository, IRoomRepository roomRepository, IUserRepository userRepository, IWindowRepository windowRepository, IChairRepository chairRepository, IDoorRepository doorRepository, IWCRepository wcRepository)
      {
          _moduleRepository = moduleRepository;
          _bookRepository = bookRepository;
          _tableRepository = tableRepository;
          _classRepository = classRepository;
          _roomRepository = roomRepository;
          _userRepository = userRepository;
          _windowRepository = windowRepository;
          _chairRepository = chairRepository;
          _doorRepository = doorRepository;
          _wcRepository = wcRepository;
      }
  
      public ActionResult Index()
      {
          ViewBag.Windows = _windowRepository.GetAllWindows();
          ViewBag.Doors = _doorRepository.GetAllDoors();
          // e.t.c.
  
          return View();
      }
  } 
  </code></pre>
  
  <p>And i have to initialize this in each of my Controller, where i need to use this repositories (Home, Admin, ...).</p>
  
  <p>So, if i could to make something like this:</p>
  
  <pre><code>public class HomeController : ApplicationController
  {
      public ActionResult Index()
      {
          ViewBag.Windows = windowRepository.GetAllWindows();
          ViewBag.Doors = doorRepository.GetAllDoors();
  
          return View();
      }
  }
  </code></pre>
  
  <p>And initialize just one time here: </p>
  
  <pre><code>public abstract class ApplicationController : Controller
  {
      public ApplicationController(IModuleRepository moduleRepository, IBookRepository bookRepository, ITableRepository tableRepository, IClassRepository classRepository, IRoomRepository roomRepository, IUserRepository userRepository, IWindowRepository windowRepository, IChairRepository chairRepository, IDoorRepository doorRepository, IWCRepository wcRepository)
      {
          // Initialize repositories just one time here
      }
  }
  </code></pre>
  
  <p>it could be very good, but i need to pass arguments in constructor of implementing class</p>