Reputation: 1793
I come from the WPF side of the world and I am used to using the MVVM pattern quite a bit. I am attempting to learn MVC and am having a little bit of difficulty trying to understand where my boundries are in MVC. Here is my scenario:
I have 3 objects, Parent, Child and GrandChild. These are custom objects, not using the built in model stuff from MVC. I have a good handle on validation stuff. I have a good handle on how to get and populate my objects. But, I am struggling to find best practices on what to do with Controllers. What should my controller be responsible for? For example, should I have one controller that understands how to CRUD Parent, Child, and GrandChild? Or should those be separated? If they should be separated, how should I do that if, when I am looking at Parent, I want to see a list of Children.
Upvotes: 2
Views: 509
Reputation: 6655
The Nerd Dinner app is a clean cut example. I agree with pushing CRUD to a repository, and in general, using the controller only for control flow.
However, in my experience with ASP.NET MVC (right or wrong), the controller ends up doing a lot of rearranging of the data before handing off to the view, and vice versa when accepting an object model as data from a form post. But again, it is just making a translation between what the View needs and what the Model needs.
Upvotes: 0
Reputation: 27421
Controller is used only for controlling the flow of the request-response. So, in your example, controller should never know how to CRUD them. CRUD logic should be wrapped in a Repository class of the model.
Take a look at the Official Nerd Dinner example and I personally love this part the most.
Upvotes: 3