It depends on the size of your project. For something small or quick prototype, I would go with the option when the controllers directly access the DbContext .
public ActionResult Index() { var list = _context.MyClass.Take(10); return View(list); }
I personally prefer to separate the concerts. In other words, I would create a class of service that passes exactly the data that it needs to the controller. Remember that the controller does not need to know how to perform tasks , but instead what needs to be done after that .
This, of course, does not mean that you need to implement a repository template. Your service class can access DbContext directly if you want.
source share