title: Play Scala Dependency injection: How to use it
body: <p>I am trying to use Play 2.5 dependency injection. I have following class which makes a call to REST api and parses the response</p>
  
  <pre><code>class Client @Inject()(ws:WSClient, baseUrl: string) {
  
    def this(ws:WSClient) = this(ws, "&lt;url string&gt;")
    def getResponse() = {....}
  ....
  
  }
  </code></pre>
  
  <p>The caller of the code looks like below</p>
  
  <pre><code>var client = new Client(WS.client)
  client.getResponse()
  </code></pre>
  
  <p>I am getting following warning.</p>
  
  <blockquote>
    <p>object WS in package ws is deprecated: Inject WSClient into your
    component</p>
  </blockquote>
  
  <p>I understand that i need to inject WS.Client instead of passing it explicitly to the Client constructor. But how do i do that?</p>
  
  <p><strong>=== Update ===</strong></p>
  
  <p>I don't want to inject Client or WSClient from the Controller. My controller creates objects and classes at run time and i want those objects to create Client Object. When i explicitly pass WS.client object to the Client object i get the above stated warning.</p>
  
  <p><strong>=== Update 2 ===</strong></p>
  
  <p>I have a plugin architecture in my application. When a a controller starts an action. It does not know what set of plugins it is going to execute. Some plugins would not need a WSClient and some of them would. So i dont want to couple the injection of WSClient into my controller. Each plugin independently decides if it wants to call a remote service. When a plugin decides to call the remote service, it should be able to inject WSClient in what ever client it wants to invoke. </p>
  
  <p>Controller Action --> Determine Plugins to Execute --> Execute Plugins ---> Plugin1 (needs to call a remote api, create a client object, per say new Client(WS.Client)). This is where the injection should happen, not at the controller.</p>