title: Example use-cases for using Dependency Injection with the Play Framework
body: <p>I am a big fan of Dependency Injection and the Play Framework, but am having trouble seeing how the two could be exploited together.</p>
  
  <p>There are modules for Spring and Guice, but the way that Play works makes it hard for me to see how DI could be beneficial beyond some quite simple cases.</p>
  
  <p>A good example of this is that Play expects JPA work to be done by static methods associated with the entity in question:</p>
  
  <pre><code>@Entity
  Person extends Model {
      public static void delete(long id) {
          em().find(id).remove();
      }
  
      //etc
  }
  </code></pre>
  
  <p>So there is no need for a <code>PersonManager</code> to be injected into controllers in the way it might for a Spring J2EE application. Instead a controller just calls <code>Person.delete(x)</code>.</p>
  
  <p>Obviously, DI is beneficial when there are interfaces with external systems, as the concrete implementation can be mocked for testing etc., but I don't see much benefit for a self-contained Play application.</p>
  
  <p>Does anyone have any good examples? Does anyone use it to inject a <code>Manager</code>-style class into <code>Controller</code>s so that a number of operations can be done within the same transaction, for example?</p>