Macwire dependencies not being fulfilled

205 views Asked by At

I am using wire in my scala project. I have a usecase ---

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("")
}

This throws an error -

Cannot find a value of type: [etl.infrastructure.endpoints.SchemaRegistryClient]

It works if I create hardcoded object of SchemaRegistryClient inside the EndpointModule.

(val c = new SchemaRegsitryClient(""))

Can anyone help in explaining how to workaround this and what is happening here?

I cant seem to find a way to fulfill the dependency.

LightweightinstructionRunner is in a diff package while SchemaRegistry and SchemaRegistryClient are in the same package.

1

There are 1 answers

5
Thilo On

The SchemaRegistryClient to be used has to be in scope for the macro to find it. You could declare an abstract def for it in your EndpointModule (without any parameter, because MacWire does not know which url to put in there)

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)
}