Modern Akka DI with Guice

后端 未结 6 1051
时光取名叫无心
时光取名叫无心 2021-02-13 19:41

Java 8, Guice 4.0 and Akka 2.3.9 here. I am trying to figure out how to annotate my actor classes with JSR330-style @Inject annotations, and then wire them all up v

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-13 20:31

    Use an akka Creator:

    public class GuiceCreator implements Creator {
     Class clz;
     Module module;
     /*Constructor*/
    
     public T create() {
        Injector injector = Guice.createInjector(this.module);
        return injector.getInstance(this.clz);
      }
    }
    

    Then use Props.create with your shiny new guice-based creator.

    Disclaimer: I don't actually know Akka, the mentioned information comes from browsing the documentation and JavaDoc.

提交回复
热议问题