Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Spring services + wbeflow actions  RSS feed

Tomasz Nawrot
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a little bit confused about using Spring services. I have met with two different approaches and not sure which one is correct (maybe not correct but better).
Recently I was developing one project and found out that services were written for each Entity. Developers had created entity Person, then PersonDao for db operation and then inject that Dao to PersonService.
The same for address: Address, AddressDao and AddressService.
There was also the method in controller to find persons with addresses so they injected AddressService to PersonService and then implemented method findPersons(...) in PersonService where they called method findAddressesForPerson(...) from AddressService.
The question which came tom my mind is: what is the reason for injecting one service into another, isn't better to inject AddressDao to PersonService instead ?

I thought that services should be more business logic based. So instead creating one service for each Entity I would rather create services name according to the business requirements. And then inject to that services as many DAO as required without worries that some DAO are used not only in one service but in more (at last they are there to be used in such a way, arent't they?)

Now next part: whole app bases on Spring webflow. Developers created XHTML file then webflow xml file. On the webpage there were two different lists of addresses: one for private address and the second for workAddresses.
To display those lists they created ViewBean which had two fields: List<PrivateAddress>, List<WorkAddress>. Address were loaded in Action's init method. That method was called from webflow file.
Action class had PersonService injected into it and they called PersonService.findPrivateAddress and then PersonService.findWorkAddress and filled the fields in the ViewBean.

How to treat Action class? For me, together with XHTML, webflow.xml and ViewBean it is the View layer, isn't it ? Or it's more like controller ?
Both methods: findPrivateAddress and findWorkAddress have common part: they called findAddressForPerson(...) from AddressService. And then make some different operations on the list of addresses.

Maybe it would make more sense to inject AddressService to Action also, call method from it first and then pass the list of address to concrete method from PersonService. From one side we let Action to know more about our services, but from the other side we have less coupling between services.

More generally how much logic can we place in controller ? Should it be the place only where we called the services and whole logic is closed within those services ?

Thanks in advance for your advices.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!