2

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!

Konstantin Bodnia
  • 1,372
  • 3
  • 20
  • 43
  • Could you post the code snippet that gives you the compile-time error, or even better, a self-contained example? – adamw Sep 26 '17 at 11:07
  • What's `self`? Perhaps you're missing this https://github.com/adamw/macwire-akka-activator/blob/master/src/main/scala/activator/actors/ActorsModule.scala – Abhijit Sarkar Dec 01 '17 at 04:35

0 Answers0