why cant I bind to single actor instance (akka router) with scaldi?

ぃ、小莉子 提交于 2019-12-25 11:27:11

问题


I´m currently struggeling with implementing my Akka router logic using scaldi for dependency injection. Why cant I bind to a single actor instance with scaldi, since my actor is a router and I only want to have one single instance of it? The way I came to ask this question was another stackoverflow entry.

My scaldi Module:

class DAOModule extends Module {
  bind toProvider new UserDaoWorker
  binding to new UserDaoRouter
}

This way only one instance is created and as soon as I inject my router multiple times it gets a dead letter actor as sender from the sender() method.

When I change the binding to...

binding toProvider new UserDaoRouter

... it works perfectly fine, but every injection means a new instance of my router. Am I right?

So how can I achieve having only a single instance of my router which is injectable?

Thanks in advance


回答1:


May be like this: bind [UserDaoRouter] to new UserDaoRouter ??




回答2:


This is what worked for me:

class DAOModule extends Module {
  binding toProvider new UserDaoWorker
  binding toProvider new UserDaoRouter
  binding identifiedBy 'singletonUserRouter to {
    implicit val system = inject[ActorSystem]
    AkkaInjectable.injectActorRef[UserDaoRouter]
  }
}

And then in my controller:

val userDaoRouter = inject[ActorRef] ('singletonUserRouter)

I hope this will help someone else ;)



来源:https://stackoverflow.com/questions/26085403/why-cant-i-bind-to-single-actor-instance-akka-router-with-scaldi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!