In which layer should I encode things

I have a solution consisting of several levels: controller> service> business> repository

I study MVC, so I try to follow the recommendations as much as possible. I think the controller should be as light as possible. Let's say we have an β€œEdit” action in my controller that gets a view model hosted by the corresponding view. This presentation model is the result of the data contained in the model object.

What should I achieve with this view model:

  • (1) get the associated object model
  • (2) map my view model to my object model (to have an updated and complete object)
  • (3) save this updated object
  • (4) prepare the notice displayed in the submission
  • (5) return to another view

My question is: where should I code all these things?

From my point of view, points 1, 2, 3 should run in the business layer, and points 4 and 5 in the controller layer.

Can you confirm?

Thanks.

+4
source share
1 answer
  • The repository has data access logic.
  • The business layer will use the repository to save the object.
  • The business layer will check business rules, send emails, etc. Most of the logic is here.
  • The controller simply uses the business layer to perform the functions.

A service class is what I call the Business layer. If you mean a web service, then the class representing the web service must internally send calls to your actual business class, otherwise you do not need an intermediate class of service between your business and the controller.

+2
source

Source: https://habr.com/ru/post/1383616/


All Articles