2

I am creating the router from Akka configuration.

val router = context.actorOf(FromConfig.props(MyActor.props), "router")

I want to unit test the Actor that the router is in, and being able to inject the router into the Actor would be helpful.

Is it possible to instead inject this router using Scaldi? I know in the Scaldi module I can bind using new.

binding toProvider new OrderProcessor

But I can't seem to find a way to create bindings from config.

Nelson
  • 2,972
  • 3
  • 23
  • 34

1 Answers1

1

The properties can be injected. In the Module

binding identifiedBy "props-from-config" to FromConfig.props(MyActor.props)

And in the Actor inject the props and create the actor.

private val propsFromConfig = inject[Props]("props-from-config")
val router: ActorRef = context.actorOf(propsFromConfig, "router")

Then in the unit test bind any props. The Actor is creating an actor from props, and does not know that the props are coming from config.

Nelson
  • 2,972
  • 3
  • 23
  • 34