我有一个 api 服务类,它依赖于 play 的 Configuration 和 WSClient 实例。
而且我不想使用 @Inject() 注释,因为我想在 Macwire 上使用编译时注入,所以我所做的是:
// this is a trait that here im wiring all the dependencies that my api service needs
trait ApiDependencies {
lazy val conf: Configuration = wire[Configuration]
lazy val wsc: WSClient = wire[WSClient]
}
// this is the api service
class ApiService extends ApiDependencies {
def getInfo (id: String): Future[Option[Info]] = {
wsc.url("...").withHttpHeaders(("Content-Type", "application/json")).get.map { response =>
response.status match {
case Status.OK => ...
case Status.NO_CONTENT => ...
case _ => throw new Exception()
}
}
}
}
但我得到一个编译器错误:
错误:找不到类型的值:[com.typesafe.config.Config]
lazy val conf:Configuration = wire[Configuration]错误:找不到公共构造函数或 [play.api.libs.ws.WSClient] 的伴随对象lazy val wsc:WSClient = wire[WSClient]
有人知道我该如何解决这个问题...?为什么会这样:/
谢谢!