Is passing around ActorRef to other Actors good or bad ?

前端 未结 2 1436

I\'m trying to figure out if my usage of passing Akka ActorRef around to other actors is not an anti-pattern.

I\'ve a few actors in my system. Some are long

2条回答
  •  孤街浪徒
    2021-02-04 00:30

    There are a couple of good ways to "introduce" actor refs to actor instances that need them.

    1) Create the actor with the refs it needs as constructor args (which is what you are doing)

    2) Pass in the needed refs with a message after the instance is created

    Your solution is perfectly acceptable, and even suggested by Roland Kuhn, the Tech Lead for Akka, in this post:

    Akka actor lookup or dependency injection

提交回复
热议问题