Macwire how to wire actorref self instance

367 views Asked by At

I'm exploring Macwire DI framework for Scala and while doing it I faced a problem.

I have a dispatcher actor that creates a bunch of actors that are dependent on the dispatcher. Dispatcher controls all the message flow between its child actors.

Here's a brief situation of my setup:

class WorkerActor(dispatcher: ActorRef) extends Actor {}

class Dispatcher extends Actor {
  private val worker = context.actorOf(Props(
    new WorkerActor(self)
  ))
}

In my real project WorkerActor has more dependencies than only one “self”. And they can be easily wired.

I tried doing this dispatcher: ActorRef @@ Dispatcher, but it gave me error:

Error:(47, 9) Cannot find a value of type: [akka.actor.ActorRef @@ Dispatcher] wire[WorkerActor]

If I was using guice, this would work like a charm:

bind[AkkaRef] annotatedWith(Names.named("Dispatcher")) toInstance self

The question is: how do I add “self” to the scope of macwire?

Or maybe I should use different approach?

Thanks!

0

There are 0 answers