Hi Chanan,

I’ll leave more specific points to Patrik, but I’d like to remark on the 
general strategy. Injecting resources into Actors for their use is a very 
reasonable thing to do, which is why IndirectActorProducer exists. Creating 
actors, however, is something which inherently must always be done by another 
actor in order to properly define the supervision hierarchy. Guice cannot 
really do that, because an ActorSystem is its own encapsulated container and 
apart from the unfortunate exception of `system.actorOf()` Guice cannot drive 
the creation—it can only be involved by the parent actor as you are doing it. 
As a side note, I dream of a world where system.actorOf() is deprecated and 
eventually removed, simply because it is such a gross and problematic hack, 
both internally and semantically.

Akka provides several ways to wire together an actor system: you can create 
child actors, pass their reference to other child actors via their constructor, 
you can introduce actors to each other by sending references in messages, and 
finally there is also `context.actorSelection` (if all else fails). Therefore I 
do not see the need to use a DI framework for injecting ActorRefs into actors, 
I believe we have covered that base already. If you have a use case which is 
not supported by these tools, please let us know!

Regards,

Roland

10 jan 2014 kl. 01:53 skrev Chanan Braunstein <[email protected]>:

> 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.



Dr. Roland Kuhn
Akka Tech Lead
Typesafe – Reactive apps on the JVM.
twitter: @rolandkuhn


-- 
>>>>>>>>>>      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.

Reply via email to