Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller - Should it deal with service layer or repository directly? [closed]

There are so many conflicting articles online. What's your personal opinion on this (for an enterprise app).....

In my C#/MVC app I've setup my architecture as suggested here, minus dependency injection and automapper: https://chsakell.com/2015/02/15/asp-net-mvc-solution-architecture-best-practices/

In general, when speaking of the MVC controller, should it only deal with the service layer directly? Or is it still good practice to deal with the repository directly? What would help you to decide?

Also, should the UnitOfWork class be created at the controllers level then passed into Service/repo?

Thanks

like image 935
WebDevGuy2 Avatar asked Sep 01 '25 10:09

WebDevGuy2


1 Answers

Well, Unit of work, I think is useless as DBContext could be the unit of work, Also you could use the DbContext as repository. Do I need repository and service layers, I think just one of them is enough depends on the complexity of the project, service is layer is when you have more complex project. You should think of how you could re-use your code, and keep it simple, but not to create a lot of layers, with non reusable code

like image 106
Tarek Abo ELkheir Avatar answered Sep 02 '25 23:09

Tarek Abo ELkheir