[scaldi-akka 0.5.8] Testing with Scaldi & Akka?

48 views
Skip to first unread message

Steve Thompson

unread,
Sep 15, 2015, 2:12:58 PM9/15/15
to scaldi
I've got test setup code for Specs2 along the following lines:

trait Setup extends Scope {
    implicit val actorSystem = ActorSystem("MyActorSystem")
    val myActor = TestActorRef[MyActor]

    implicit val injectors = new Module {
      bind [ActorSystem] to actorSystem
      bind toProvider myActor
   }
}

Unfortunately this doesn't work too well. My suspicion is that toProvider wants to create an ActorRef, and in this case myActor is already an ActorRef. Any guidance you could provide would be greatly appreciated.

Thanks and best regards,


Steve
--

Oleg Ilyenko

unread,
Sep 15, 2015, 2:36:28 PM9/15/15
to scaldi
Hi Steve,

Since you have created a test actor ref beforehand, `toProvider` would give the same instance every time it is injected. On the other hand the code you have shown looks a bit unusual to me. The binding `bind toProvider myActor` will have only one identifier of type `ActorRef`. For such a generic types I would always recommend to use additional identifiers (like string for example: `bind [ActorRef] identifiedBy "paymentProcessor" toProvider myActor`) in order to disambiguate it. Otherwise you can only define it only once in DI container.

I find it hard to give a suggestion based on the code you have shown. It would be very helpful if you could demonstrate how this actor or `ActorRef` is used in application (non-test) code. (I assume that you are overriding some existing application's `ActorRef` in the test with `TestActorRef`)

Cheers,
Oleg
Reply all
Reply to author
Forward
0 new messages