Bronzato
Bronzato

Reputation: 9342

In which layer do I have to code things

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:

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.

Upvotes: 4

Views: 117

Answers (1)

Muhammad Hasan Khan
Muhammad Hasan Khan

Reputation: 35136

  • Repository has data access logic.
  • Business layer will use repository to persist the object
  • Business layer will check business rules, send emails, etc. Most logic goes here.
  • Controller just uses the Business layer to perform the functionality.

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.

Upvotes: 2

Related Questions