1

我在我的 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对象,它就可以工作。

(val c = new SchemaRegsitryClient(""))

谁能帮助解释如何解决这个问题以及这里发生了什么?

我似乎无法找到一种方法来满足依赖。

LightweightinstructionRunner在一个 diff 包中,而SchemaRegistrySchemaRegistryClient在同一个包中。

4

1 回答 1

3

SchemaRegistryClient要使用的 必须在宏的范围内才能找到它。def你可以在你的EndpointModule(不带任何参数,因为 MacWire 不知道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)
}
于 2020-05-24T12:34:58.233 回答