Blankman
Blankman

Reputation: 267140

How to get Play current when using it in a trait?

I'm trying to migrate my older play application to the new play version where you use DI to get the Play.current value.

How can I use an injected Application when I am currently using it in a trait like this:

trait SomeTrait {

  lazy val someThing = WrapApp(Play.current)
}

@Singleton
class MyApi @Inject() (currentApplication: Application) extends SomeTrait {

}

I'm not sure how to pass the play.api.Application instance to my trait now?

Upvotes: 2

Views: 38

Answers (1)

danielnixon
danielnixon

Reputation: 4268

trait SomeTrait {

  def currentApplication: Application

  lazy val someThing = WrapApp(currentApplication)
}

@Singleton
class MyApi @Inject() (override val currentApplication: Application) extends SomeTrait {

}

Upvotes: 1

Related Questions