I have a service that needs information implemented by another service in the same layer. Is it good practice for one service to take a dependency on another service in the same layer?
-
2I would think that the best practice is to extract the part that's used in both web services, and have both services use that. – user16764 Mar 02 '14 at 19:14
3 Answers
Yes. I have seen architectural diagrams of SOA (Service Oriented Architecture) where exactly this happens. A service should be written in such a way that it doesn't care if user is calling it, a service in the 'same layer', or it is being combined into a composite service.
The Open Group SOA Reference Architecture diagram shows services calling services in the 'same layer': Figure 22-2 (http://pubs.opengroup.org/architecture/togaf91-doc/arch/chap22.html)
The Open Service Integration Maturity Model (OSIMM) is also a good diagram, the link is talking about IBM Process Server but Kim Clark and Brian Petrini give a really good explanation: Figure 1 (http://www.ibm.com/developerworks/websphere/library/techarticles/0904_clark/0904_clark.html)

- 3,053
- 19
- 26
I use my services within each other. This way I am able to reuse my service methods, instead of copying algorithms all over the layer.
In my experience, one thing to be aware of is circular dependency.
When initializing a service class, say in the constructor, initializing other service object fields may lead to never ending circular calling if the field also depends on the initializing service.
When calling a method, a service method may call another service call and that may also call another service method which can lead to circular call again.

- 2,089
- 1
- 13
- 16