Issue
I am pretty new working with the MVC pattern (Spring MVC). I have a very simple question. Can a service have a dependency on another service? something like:
@Service
public class MyFirstService{
.....
@Autowired
private MySecondService secondService;
......
}
Is this a "good practice" or is something that should be avoided?
Thanks!
Solution
There is a simple answer: yes.
One service depending on another service makes sense. Else it is possible that you have code duplications.
One example that comes into mind is having an EmailService
. I don't want to write email sending code several times so that I create a service out of this. This service would be called by other services naturally.
Answered By - Uwe Plonus
Answer Checked By - Robin (JavaFixing Admin)