asp.net mvc3, why do we need service layer when we use repository pattern
-
29-10-2019 - |
Question
I was watching "storefront starter kit", its using repository pattern with service layer. In the video, he didnt really explain why he's using service layer. Seems like those are just extra.
what are pros and cons using service layer?
Solution
For most asp.net mvc apps it is perfectly reasonable and preferable for your controllers to directly address the repository (via an interface). I would only add a service layer when you need to, for example when other apps are interfacing with your application. In my opinion you should avoid unnecessary abstraction layers.
OTHER TIPS
Repository is your Data Layer ... it's responsibility is to fetch and save data.
The Service Layer is your Business Layer ... it's responsibility is to hold all your business logic.