首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未满足Macwire依赖关系

未满足Macwire依赖关系
EN

Stack Overflow用户
提问于 2020-05-24 12:26:22
回答 1查看 134关注 0票数 1

我正在我的scala项目中使用连线。我有个usecase --

代码语言:javascript
复制
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:

找不到类型的值

如果我在SchemaRegistryClient中创建硬编码的EndpointModule.对象,它就能工作。

代码语言:javascript
复制
(val c = new SchemaRegsitryClient(""))

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2020-05-24 12:34:58

要使用的SchemaRegistryClient必须在宏的范围内才能找到它。您可以在您的def中为它声明一个抽象的EndpointModule (没有任何参数,因为MacWire不知道在其中放哪个url )。

代码语言:javascript
复制
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)
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61985950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档