I do not always have static values ββ(slogan, banner, description ...) and PartialViews (block_head, block_footer, block_right) where I have to display it. Therefore, I need to transfer a large collection of these values ββto Partial in each Action, and this is not very good for me.
I found an interesting solution here: http://www.asp.net/mvc/tutorials/passing-data-to-view-master-pages-cs , partially "Good Solution". I could move all the initialization of these values ββto the ApplicationController and implement it from my controllers.
But I would like to go ahead and initialize my interfaces in the ApplicationController too :) If I could do this, I think it should be fantastic. I use Ninject, therefore, some code:
public abstract class ApplicationController : Controller {
Implementation:
public class HomeController : ApplicationController {
Only one problem, I donβt know how to implement ApplicationController if it has arguments. Is this a good way and is this a solution to my problem? In the future I am going to install 5-7 interfaces and have about 10-15 controllers, so it would be very useful to initialize them all in ApplicationController and implement them in another. Thank you, sorry if the questionnaire is stupid.
Ok by adding:
Now, if I have 10 interfaces, it should be something like this:
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();
And I have to initialize this in each of my controllers, where I need to use these repositories (Home, Admin, ...).
So, if I could do something like this:
public class HomeController : ApplicationController { public ActionResult Index() { ViewBag.Windows = windowRepository.GetAllWindows(); ViewBag.Doors = doorRepository.GetAllDoors(); return View(); } }
And initialize only once here:
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) {
this may be very good, but I need to pass arguments in the constructor of the implementing class