3
votes

I am migrating my application to Play 2.5 and I have the following issue:

import play.modules.reactivemongo.ReactiveMongoApi

trait Foo {
  override def reactiveMongoApi: ReactiveMongoApi = current.injector.instanceOf[ReactiveMongoApi]
  ...
}
object Foo extends Foo

As current is now deprecated, I would like to replace it. However, I can't use @Inject() (val reactiveMongoApi: ReactiveMongoApi) as I am in a Trait. How am I supposed to do it ?

1

1 Answers

3
votes

You can do something like this:

import play.modules.reactivemongo.ReactiveMongoApi

trait Foo {
  def reactiveMongoApi: ReactiveMongoApi

  // other methods
}

@Singleton
class FooClass @Inject()(reactiveMongoApi: ReactiveMongoApi) extends Foo {
    // other methods
}

Notice how the property name in FooClass (reactiveMongoApi) matches the method defined at the trait Foo. After that, you can declare a module to provide the correct bindings.