Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • 2
    This answer feels halfway between a comment and an answer. You. could make. it a. better answer by. focusing on and spelling out your answer to OP's question, then talking about why the approach described in the accepted answer is something one "should not be doing". I could +1 an answer like that. Commented Aug 30, 2020 at 19:26
  • 1
    I was agreeing with this answer until I saw that a service could inject other repositories. If the service layer has business logic in it, it would be great to bypass that and go to the repository directly. Commented Dec 22, 2020 at 19:13
  • @Cristian I didn't fully understand your comment. If you were disagreeing with the fact that a service could talk to multiple repos, I would like to know why. In my defense, the example discussed here might not have the best terminology. The service could be a 'MemberService' where you deal with customers who actually have registered with you already (members). Commented Dec 22, 2020 at 20:00
  • Not every service is at the same level. For example it is not uncommon for a microservice to have other "services" that are not exposed to the outside world. I would agree in fact that the microservice should handle the translation to DTOs. But I don't agree that you need to add that complexity if you are not transferring objects. Commented Mar 28, 2022 at 11:26
  • " Instead, the service layer should encapsulate your domain model and return DTOs via its interface" What is the benefit of this? Commented Apr 16, 2024 at 23:53