依旧注入Akka

 靈幻雪月 发布于 2023-02-07 10:22

我在我的应用程序中使用Guice非常多.最近我开始学习akka演员,感觉就像用它重构我的应用程序.

无论如何,我已经想知道我的所有guice将如何与演员合作.我继续搜索谷歌,它有点混乱.

我在这个主题上找到的最新文档是论文:

http://letitcrash.com/post/55958814293/akka-dependency-injection

http://eng.42go.com/tag/guice/

哪个不提倡相同的事情.

我必须承认我仍然需要阅读很多,我正在学习akka的开始.我做了一些例子和一些简单的事情,但我不想深入了解后来会发现我会遇到很多问题.

所以我的问题是截至今天,关于如何使用依赖注入的Akka Actors的共识是什么.

什么样的注射可能?我们可以将演员与对象/其他演员/ ....

无论如何,请以简洁的方式概述一些可以帮助我理解什么是可能的以及什么是最佳实践的东西?

1 个回答
  • 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."

    2023-02-07 10:24 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有