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?
1
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) has a good diagram if you search for it. There used to be a good write up from Kim Clark and Brian Petrini but IBM have annoyingly taken down the ‘old’ content (original link, wayback machine as it was but no images, low res version but most likely to stay up, University of Vienna)
0
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.
you could use “chain of responsibility” design pattern to achieve this.
http://www.blackwasp.co.uk/ChainOfResponsibility.aspx