【发布时间】:2017-12-07 20:46:32
【问题描述】:
我有一个依赖于 play 的 Configuration 和 WSClient 实例的 api 服务类。
我不想使用 @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]
惰性验证配置:配置 = 线 [配置]错误:找不到公共构造函数或伴生对象 [play.api.libs.ws.WSClient] 懒惰的 val wsc: WSClient = wire[WSClient]
有人知道我该如何解决这个问题...?为什么会这样:/
谢谢!
【问题讨论】:
标签: java scala dependency-injection playframework macwire