ActorModule

play.api.libs.concurrent.ActorModule
See theActorModule companion object
@ApiMayChange
trait ActorModule extends AbstractModule

Facilitates runtime dependency injection of "functional programming"-style actor behaviors.

  1. Mix this trait into the object defining the actor message(s) and behavior(s);
  2. Define the Message type with actor message class;
  3. Annotate with Provides the "create" method that returns the (possibly just initial) Behavior of the actor;
  4. Use the bindTypedActor in PekkoGuiceSupport, passing the object as 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 AbstractModule
trait Module
class Object
trait Matchable
class Any

Members list

Type members

Types

type Message

Value members

Inherited methods

final def configure(builder: Binder): Unit

Attributes

Inherited from:
AbstractModule