I need help with regards to dependency injection in akka-typed; Aside of constructor injection, do we have any other injection type that can be used without the need for an external library? e.g (property injection).
It becoming overwhelming to have only constructor injection everywhere, especially when the project is getting bigger(code wise).
What is the lifecycle of the dependencies and the actor?
The equivalent for actor property injection would be via sending / telling a message as long as the value passed in is thread-safe.
Are you using Scala or Java or …?
You could always use a singleton that implements one or more traits wrapping all your dependencies and default it in the constructor so it is only replaced in tests.
You could also make the constructor dependencies implicit.
Do you have some example code?
I know this is an external library, and you might have already found it, but there is a issue discussing it.
Thanks @octonato, primarily, what I wanted to mitigate injecting was utility actors e.g emailServiceActor,
NotificationServiceActor - for publishing errors to discord and sms. Since these actors are needed in almost 90% of the other actors, I thought of how they can be injected not via the constructor.
Since those seem like they’d be instance singletons, you could have actors discover them at startup by interacting with the ActorSystem's guardian actor (the receptionist would also be viable, but in a cluster scenario I’m not aware of an easy means of preferring a local instance). Spawn an actor which needs some dependency, it asks the guardian or the receptionist and might stash incoming messages until it gets the dependency.