Search code examples
scaladependency-injectionplayframeworkguice

partial parameter list injection on play framework


given a class

class Foo @Inject()(cfg: Config, private val emr: AmazonElasticMapReduce = AmazonElasticMapReduceClientBuilder.defaultClient())
                             (implicit actorSystem: ActorSystem, ec: ExecutionContext) 

play framework fails when it tries to Inject the 'emr' value.

I don't want play to inject it, instead I want to use the default value. Is it possible to define?


Solution

  • You need to add to your Module.scala:

    bind(classOf[AmazonElasticMapReduce]).toInstance(AmazonElasticMapReduceClientBuilder.defaultClient()).asEagerSingleton()
    

    Instead of trying to provide it to the constructor.

    If you don't want it injected at all, you can have it just as a member in the class.