我在我的应用程序中使用Guice非常多.最近我开始学习akka演员,感觉就像用它重构我的应用程序.
无论如何,我已经想知道我的所有guice将如何与演员合作.我继续搜索谷歌,它有点混乱.
我在这个主题上找到的最新文档是论文:
http://letitcrash.com/post/55958814293/akka-dependency-injection
http://eng.42go.com/tag/guice/
哪个不提倡相同的事情.
我必须承认我仍然需要阅读很多,我正在学习akka的开始.我做了一些例子和一些简单的事情,但我不想深入了解后来会发现我会遇到很多问题.
所以我的问题是截至今天,关于如何使用依赖注入的Akka Actors的共识是什么.
什么样的注射可能?我们可以将演员与对象/其他演员/ ....
无论如何,请以简洁的方式概述一些可以帮助我理解什么是可能的以及什么是最佳实践的东西?
I know you are working in Akka with Guice and Scala, but Typesafe provides a tutorial describing how things work in Akka with Spring and Java. This can provide a good starting point for understanding how dependency injection fits into the Actor
lifecycle for your situation.
Meanwhile, here is some sample code from their documentation for using a factory method to inject constructor arguments:
class DependencyInjector(applicationContext: AnyRef, beanName: String) extends IndirectActorProducer { override def actorClass = classOf[Actor] override def produce = // obtain fresh Actor instance from DI framework ... } val actorRef = system.actorOf(Props(classOf[DependencyInjector], applicationContext, "hello"), "helloBean")
Here are some guidelines compiled by Typesafe on the matter.
Finally, note the following from the documentation:
"When using a dependency injection framework, actor beans MUST NOT have singleton scope."