play.api.libs.concurrent.ActorModule
See theActorModule companion object
@ApiMayChange
trait ActorModule extends AbstractModule
Facilitates runtime dependency injection of "functional programming"-style actor behaviors.
- Mix this trait into the
objectdefining the actor message(s) and behavior(s); - Define the
Messagetype with actor message class; - Annotate with Provides the "create" method that returns the (possibly just initial) Behavior of the actor;
- Use the
bindTypedActorin PekkoGuiceSupport, passing theobjectas the actor module.
For example:
object ConfiguredActor extends ActorModule {
type Message = GetConfig
final case class GetConfig(replyTo: ActorRef[String])
@Provides def apply(configuration: Configuration): Behavior[GetConfig] = {
// TODO: Define ConfiguredActor's behavior using the injected configuration.
Behaviors.empty
}
}
final class AppModule extends AbstractModule with PekkoGuiceSupport {
override def configure() = {
bindTypedActor(ConfiguredActor, "configured-actor")
}
}
Message is a type member rather than a type parameter is because you can't define, using the example above, GetConfig inside the object and also have the object extend ActorModule[ConfiguredActor.GetConfig].
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
-
class AbstractModuletrait Moduleclass Objecttrait Matchableclass Any
Members list
In this article