Scala 在特质中使用时,如何获得当前的游戏?

Scala 在特质中使用时,如何获得当前的游戏?,scala,playframework,Scala,Playframework,我正在尝试将旧的play应用程序迁移到新的play版本,在该版本中,您可以使用DI获取play.current值 当我当前使用注入式应用程序时,如何使用它 trait SomeTrait { lazy val someThing = WrapApp(Play.current) } @Singleton class MyApi @Inject() (currentApplication: Application) extends SomeTrait { } 我现在不知道如何将play.

我正在尝试将旧的play应用程序迁移到新的play版本,在该版本中,您可以使用DI获取play.current值

当我当前使用注入式应用程序时,如何使用它

trait SomeTrait {

  lazy val someThing = WrapApp(Play.current)
}

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

}

我现在不知道如何将play.api.Application实例传递给我的trait?

注入整个
应用程序通常是个坏主意,因为这会使组件难以测试。相反,想想你的特质具体依赖于什么,然后注入它(例如,
配置
)。
trait SomeTrait {

  def currentApplication: Application

  lazy val someThing = WrapApp(currentApplication)
}

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

}