title: Java EE Service dependencies
body: <p>I hope this question is not too abstract. This is about Java EE architecture or design of Services.
  I have two business logics (simplified here for ease of reading):</p>
  
  <pre><code>@Stateless
  @LocalBean
  public class EmailService {
  
    @EJB
    private SomeBean someBean;
    // ... some other EJBs to acces the DB layer (and using JPA)
  
    public void sendEmail(String recipient /* some parameters */) {
       // ... some email sending logic here
  
    }
  }
  
  @Stateless
  @LocalBean
  public class ExecutePaymentService {
  
    @EJB
    private UserBean userBean;
    // ... some other EJBs to acces the DB layer (and using JPA)
  
    public void executePayment(int amount, int userId) {
       // ... some payment logic here
       // NEED TO SEND EMAIL HERE
    }
  }
  </code></pre>
  
  <p>The design I have is that the JSF Managed Beans are calling the above services. My issue is that the Managed Beans contain some logic:<br>
  - execute the payment<br>
  - IF payment is successful send email<br>
  - IF not do something else</p>
  
  <p>I want to have this logic in the Service EJBs so the Managed Beans are only gathering input and returning result.</p>
  
  <p>The other options is that <code>ExecutePaymentService</code> extends <code>EmailService</code> then call the sendEmail stuff. This can lead to a huge inheritance tree to be able to provide any service from any service, harder to maintain on long run and big application.... Since most of the services need to have EJB injected to access database I can't use non-EJB services....</p>
  
  <p>What would be a better way to allow a <code>service to call another service</code>?</p>