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.

7
  • 3
    Well said! My preference is to call repositories, and only in cases, then a repository is not enough (i.e. two entities must be modified by using different repositories), I create a service which is responsible of this operation and call it from the controller. Commented May 11, 2018 at 19:19
  • I had notice a rather complicated code just to justify the use of a service. Absurd, the least... Commented Jan 16, 2019 at 14:35
  • So my repository returns a list of 'business objects' that I need to convert into 'xml objects', is that reason enough to have a service layer? I'm calling a method on each object to convert it to another type and add to a new list. Commented Oct 24, 2019 at 9:02
  • 1
    Direct DAO Access is dangerous in controllers, it can make you susceptible for SQL injections and gives access to dangerous actions like ,,deleteAll'' I would definitely avoid it. Commented Oct 28, 2019 at 15:05
  • @Anirudh Calling services that call DAO doesnt prevent SQL injections either. It could even be worse if you forgot your checks in one specific service. IMO it is best to sanitize/check inputs first in the controller flow, by callin a reusable service. Then when this step is handled, you can access DAO simply from controller, and if you need more logic, you can use services, pass DAO to them, and call DAO directly from them. I like to use controllers as a dispatcher calling services, dao, and views generators. Commented Dec 7, 2020 at 10:16