Dependency injection with abstract class and object in Play Framework 2.5 : <p>I'm trying to migrate from Play 2.4 to 2.5 avoiding deprecated stuff.</p>

<p>I had an <code>abstract class Microservice</code> from which I created some objects. Some functions of the <code>Microservice</code> class used <code>play.api.libs.ws.WS</code> to make HTTP requests and also <code>play.Play.application.configuration</code> to read the configuration.</p>

<p>Previously, all I needed was some imports like:</p>

<pre><code>import play.api.libs.ws._
import play.api.Play.current
import play.api.libs.concurrent.Execution.Implicits.defaultContext
</code></pre>

<p>But now you <a href="https://www.playframework.com/documentation/2.5.x/ScalaWS">should use dependency injection to use <code>WS</code></a> and also <a href="https://www.playframework.com/documentation/2.5.x/Migration25#Deprecated-play.Play-and-play.api.Play-methods">to use access the current Play application</a>.</p>

<p>I have something like this (shortened):</p>

<pre><code>abstract class Microservice(serviceName: String) {
    // ...
    protected lazy val serviceURL: String = play.Play.application.configuration.getString(s"microservice.$serviceName.url")
    // ...and functions using WS.url()...
}
</code></pre>

<p>An object looks something like this (shortened):</p>

<pre><code>object HelloWorldService extends Microservice("helloWorld") {
    // ...
}
</code></pre>

<p>Unfortunately I don't understand how I get all the stuff (WS, configuration, ExecutionContect) into the abstract class to make it work.</p>

<p>I tried to change it to:</p>

<pre><code>abstract class Microservice @Inject() (serviceName: String, ws: WSClient, configuration: play.api.Configuration)(implicit context: scala.concurrent.ExecutionContext) {
    // ...
}
</code></pre>

<p>But this doesn't solve the problem, because now I have to change the object too, and I can't figure out how.</p>

<p>I tried to turn the <code>object</code> into a <code>@Singleton class</code>, like:</p>

<pre><code>@Singleton
class HelloWorldService @Inject() (implicit ec: scala.concurrent.ExecutionContext) extends Microservice ("helloWorld", ws: WSClient, configuration: play.api.Configuration) { /* ... */ }
</code></pre>

<p>I tried all sorts of combinations, but I'm not getting anywhere and I feel I'm not really on the right track here.</p>

<p>Any ideas how I can use things like WS the proper way (not using deprecated methods) without making things so complicated?</p>
