Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can services in the service layer communicate with each other?

I have a Service Layer, in which my PredictionService needs to know if a certain Race exists. The RaceService has a method DoesRaceExist(), but I am not sure if the services can communicate.

That also leads me to some other problems. Lets say I have an Predictions.aspx page. I implement with MVP, and so when the page is first requested, the Initialize() method in the presenter runs. The Predictions.aspx needs multiple pieces of information, from predictions and from races, maybe even more. Should I ask all these pieces from their appropriate services, or should I query the database just one time and get all the information that I need in one go? The problem is then which Service to pick, and then that the service probably does more than just relaying what it is intended for.

What is the best way to go about?

like image 934
Garth Marenghi Avatar asked Apr 23 '11 14:04

Garth Marenghi


1 Answers

If serviceA needs to get data or run a action on serviceB, it is fine to call serviceB from serviceA.

You might, however, find yourself in a situation where services call each other all over the place - if that happens, consider using a facade that orchestrates the different services (so they don't call each other directly).

like image 54
Oded Avatar answered Sep 28 '22 12:09

Oded