Interface PekkoGuiceSupport


  • public interface PekkoGuiceSupport
    Support for binding actors with Guice.

    Mix this interface in with a Guice AbstractModule to get convenient support for binding actors. For example:

     public class MyModule extends AbstractModule implements PekkoGuiceSupport {
       protected void configure() {
         bindActor(MyActor.class, "myActor");
         bindTypedActor(HelloActor.class, "hello-actor");
       }
     }
     

    Then to use the above actor in your application, add a qualified injected dependency, like so:

     public class MyController extends Controller {
       @Inject @Named("myActor") ActorRef myActor;
       @Inject ActorRef<HelloActor.SayHello> helloActor;
       ...
     }
     
    • Method Detail

      • bindActor

        default <T extends Actor> void bindActor​(Class<T> actorClass,
                                                 String name,
                                                 Function<Props,​Props> props)
        Bind an actor.

        This will cause the actor to be instantiated by Guice, allowing it to be dependency injected itself. It will bind the returned ActorRef for the actor will be bound, qualified with the passed in name, so that it can be injected into other components.

        Type Parameters:
        T - the actor type.
        Parameters:
        actorClass - The class that implements the actor.
        name - The name of the actor.
        props - A function to provide props for the actor. The props passed in will just describe how to create the actor, this function can be used to provide additional configuration such as router and dispatcher configuration.
      • bindActor

        default <T extends Actor> void bindActor​(Class<T> actorClass,
                                                 String name)
        Bind an actor.

        This will cause the actor to be instantiated by Guice, allowing it to be dependency injected itself. It will bind the returned ActorRef for the actor will be bound, qualified with the passed in name, so that it can be injected into other components.

        Type Parameters:
        T - the actor type.
        Parameters:
        actorClass - The class that implements the actor.
        name - The name of the actor.
      • bindActorFactory

        default <T extends Actor> void bindActorFactory​(Class<T> actorClass,
                                                        Class<?> factoryClass)
        Bind an actor factory.

        This is useful for when you want to have child actors injected, and want to pass parameters into them, as well as have Guice provide some of the parameters. It is intended to be used with Guice's AssistedInject feature.

        See Dependency-injecting-child-actors

        Type Parameters:
        T - the actor type.
        Parameters:
        actorClass - The class that implements the actor.
        factoryClass - The factory interface for creating the actor.