简体   繁体   中英

Crud operations in one controller is good or bad MVC behavior?

I need to know is the next against MVC or not? I have models A,B,C, and there are two main controllers CMS and Site. My Team leader say we'll just put the crud operations for A,B,C (gets to Site) and (puts in CMS).

I didn't agree with that and I wanted to have a controller for each model. Why the heck we group all functions in one place. so what should I do am I wrong ? is that good for the future of the project ? specially I'm responsible for so many operations and tasks to come in the near future and I would hate to work on such crowded and unfriendly code design.

I feel like CRUD operations should be handled by a model. The controller can then use said model to perform CRUD operations allowing the Model to hold the application logic keeping your controller "skinny".

This is assuming that your models represent business objects.

How to divide out your operations per controller is pretty much personal preference. I think there is some value to dividing the controllers into logical parts that reflect the model, since it makes them easier to manage.

Some implementations actually handle all of the crud operations in a service, which can contain multiple repositories and can perform business operations that require more than one repository. This design is usually fitting for larger projects, however for smaller projects it may be overkill.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM