[英]Macwire dependencies not being fulfilled
我在我的 scala 项目中使用电线。 我有一个用例---
class SchemaRegistry(registry: SchemaRegistryClient)
class SchemaRegistryClient(url: String) extends RestService(url) {}
trait EndpointModule {
// Schema Registry endpoint dependency
lazy val schemaRegistry: SchemaRegistry = wire[SchemaRegistry]
def schemaRegistryClient(url: String): SchemaRegistryClient = wire[SchemaRegistryClient]
}
object LightweightinstructionRunner extends EndpointModule with ConfigModule {
val client = schemaRegistryClient("")
}
这会引发错误 -
找不到类型的值:[etl.infrastructure.endpoints.SchemaRegistryClient]
如果我在EndpointModule内创建SchemaRegistryClient的硬编码 object ,它将起作用。
(val c = new SchemaRegsitryClient(""))
谁能帮助解释如何解决这个问题以及这里发生了什么?
我似乎无法找到一种方法来满足依赖。
LightweightinstructionRunner位于不同的 package 中,而SchemaRegistry和SchemaRegistryClient位于相同的 package 中。
要使用的SchemaRegistryClient
必须位于 scope 中,宏才能找到它。 您可以在EndpointModule
中为其声明一个抽象定义(不带任何参数,因为def
不知道将哪个url
放在那里)
trait EndpointModule {
// Schema Registry endpoint dependency
def client: SchemaRegistryClient
lazy val schemaRegistry: SchemaRegistry = wire[SchemaRegistry]
}
object LightweightinstructionRunner extends EndpointModule with ConfigModule {
override val client = SchemaRegistryClient("")
}
// or maybe
class LightweightinstructionRunner(url: String) extends EndpointModule with ConfigModule {
override val client = SchemaRegistryClient(url)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.