@Inject object null: Play dependency injection
<p>I instantiated using dependency injection in my controller class. When i try to use that object using @inject annotation elsewhere, i get null value. Here is my code skeleton.</p>

<pre><code>@singleton
class ServiceClient(ws: WSClient, config: Configuration) {
 def get response() {...}
}

class App @Inject()(client: ServiceClient) extends Controller {

   def getItems = Action  {
     Obj()
   }
}

case class Obj() {

  @Inject
  var client: ServiceClient = _
  def doStuff() {
    client.getResponse() //client is null so get null pointer exception.
    ....
  }
}
</code></pre>

<p>The @Inject in Obj never seems to be working. and my client object is always null. (I do not want to pass client as param to Obj.)  My expectation was that ServiceClient object created in controller should have been injected in Obj(). What did i do wrong?</p>

<p><strong>update</strong></p>

<p>Injecting Obj to the controller, is not an option. (In my app Obj are instantiated at run time my some complicated rule, using reflection).Also i dont want to have the constructor injection in the Obj.  <strong>I am looking for field injection of ServiceClient outside of the controller.</strong></p>

<p><strong>update2</strong></p>

<p>I was able to solve the problem using</p>

<pre><code>var client: ServiceClient = play.api.Play.current.injector.instanceOf(classOf[ServiceClient]) 
</code></pre>

<p>in the Obj class.
However, play.api.Play.current is deprecated in play 2.5 so i am still kind of stuck with a warning.</p>