You are fully right on the principle. The MVCMVC should have the business logic and the data access layer in the Model. The Controller should manage user input and transforms it into commands either for the View or for the Model. There should be no buisnessbusiness logic herein an MVC controller.
But the code snippetcode snippet you show (from here?) from the controller does not seem to infringe this segregation of concerns:
It‘s not business logic: its logic is to, but a query of the model to create a view. So typically the coordination things that an MWC controller does.
You may be confused to think that it accesses the DB directly. But it appears that (_context_context
is not a db context, but an MvcContextbut an MvcMovieContext
, i.e. an object to access the model)that is part of the model. It uses the result to create a View.
But it’s not completely classical MVC either. In the original MVC, the logic would be to create a view and passing it it the id, and let the view query the model (andfor the model notifyclarity of the view if data changes). The snippet‘s approach looks more like an MVP to me, where P istutorial we could indeed regret that the mediator between model and view.
MvcMovieContext
inherits from a DbContext, a shortcut that might leak some implementation details outside the model.- The separation of concerns does not fully match the classical MVC. In the original MVC, the logic would be to create a view and passing it the
id
, and let the view query the model (and the model notify the view if data changes). In this regard, your snippet‘s approach looks more like an MVP to me, where P is the mediator between model and view.