How to create child actors with dependency injection #5854
Replies: 2 comments 4 replies
-
@Kosntantin |
Beta Was this translation helpful? Give feedback.
-
It is .NET 6 and the Akka version is 1.4.37. It is a Worker service, so still a HostedService but not ASP. I am using the new Akka.DependencyInjection package to create the supervisor actor but I am not sure how to create the child actors using the package. This is why I used the depricated. I have nothing that restricts me to using the old pakcage. Can you show me how to use the new one to create child actors? |
Beta Was this translation helpful? Give feedback.
-
I want to use akka for concurrent message processing. I am working with objects called Fixture. My design is to have a supervisor actor that gets all the messages and then routes them to another actor that handles all messages for the specific Fixture. To do this I have a dictionary of <FixtureID,IActorRef> in the supervisor actor. Naturally, if the supervisor receives a message for a Fixture that currently has no IActorRef, the supervisor needs to create a child actor and add it the dictionary. This is where I run into trouble. I am unable to create a child actor because it cannot resolve the dependencies.
This is how I register the supervising actor so I can pass it to the class that will send him the messages:
This is how I create child actors in the supervisor:
Context.ActorOf(Context.DI().Props<FixtureActor>(), $"FixtureActor{message.Id}");
The supervisor actor is created successfully but when it tries to spawn a child actor it throws this error: 'The Dependency Resolver has not been configured yet'
My code is based on this: https://getakka.net/articles/actors/dependency-injection.html Note: I do not want to use another DI Container.
Beta Was this translation helpful? Give feedback.
All reactions