I have a solution composed of several layers: controller > service > business > repository
I’m learning MVC so I try as much as possible to follow best practices. I think the controller must be as light as possible. Let’s say we have an Edit action in my controller receiving a view model posted by the corresponding view. This view model is a substract of data contained in a model object.
What I have to achieve with this view model:
- (1) retrieve the associated object model
- (2) map my view model into my object model (in order to have an updated and complete object)
- (3) save this updated object
- (4) prepare a notification to be displayed in the view
- (5) return to another view
My question: where do I have to code all these things?
In my point of view, the points 1, 2, 3 must be done in a business layer and the points 4 and 5 in the controller layer.
Can you confirm?
Thanks.
Service class is what I refer to as a Business layer. If you mean a Web Service by that then the class representing the web service should internally be dispatching calls to your actual Business class otherwise you don’t need an intermediate Service class between your Business and Controller.