You could mark an implicit parameter with annotation @Named and define a binding for the "named" ExecutionContext.
class MyClass @Inject() (ws: WSClient)
(implicit @Named("myEC") executionContext: ExecutionContext)
The binding:
package my.modules
import scala.concurrent.ExecutionContext
import com.google.inject.AbstractModule
import com.google.inject.name.Names
class MyExecutionContextModule extends AbstractModule {
override def configure(): Unit = {
bind(classOf[ExecutionContext]).annotatedWith(Names.named("myEC"))
.to(classOf[MyExecutionContextImpl])
// .toInstance(myExecutionContext)
}
}
Then you need to enable the module in Play configuration
play.modules.enabled += "my.modules.MyExecutionContextModule"
See Guice docs for more information about annotations. You can also define your own annotation or create a Module to bind implementation for your MyClass class (then it is better to make it a trait and implement it in a different class). The only Play specific thing here is that you need to enable module in config if you define one.
ws
while declaring a class that has one implicit parameter. See playframework.com/documentation/2.5.x/… – ShangrilaPlay
provides an implicitExecutionContext
to any guice-injected instance, though I can't still find where this behaviour is implemented or documented. – Rant