Hello,
We have been using @Names & @Provides from Guice to register actors to be
injected in Play controllers like so:
@Provides @Named("NewAppActor")
ActorRef getNewAppActor() {
*Return* Akka.system().actorOf(NewAppActor.Props(), "NewAppActor");
}
Where .Props() is a static method that returns a Props object.
This works fine but 2 problems:
1. As our system grows we have a need to inject services into the actors as
well. We found a way to do so by implementing IndirectActorProducer like so:
public class GuiceInjectedActor implements IndirectActorProducer {
final Injector injector;
final Class<? extends Actor> actorClass;
public GuiceInjectedActor(Injector injector, Class<? extends Actor>
actorClass) {
this.injector = injector;
this.actorClass = actorClass;
}
@Override
public Class<? extends Actor> actorClass() {
return actorClass;
}
@Override
public Actor produce() {
return injector.getInstance(actorClass);
}
}
This injects any services we have defined and works well. The problem is
that we can use this class inside our @Provides method since that @Provides
method is defined in the GuiceModule, so the injector does not exist yet.
2) As the system grows we have more and more classes defined in
GuiceModule. We would like a way to automatically register our actors
within Guice. We found a mention of this in a stackoverflow answer here:
http://stackoverflow.com/a/13947079
- but when we look in Github, we don't see the classes mentioned and we
aren't sure how to use those from Java anyway.
So, does anyone know how to either: register actors in Guice that have
services themselves and/or automatically registers actors with the @Names
attribute?
Thanks,
Chanan.
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/groups/opt_out.