C
C#2y ago
pedroavila

❔ Persist a record with Akka.Net

I have created an actor that calls to the service the create method which calls the same method that is in the repository public class UserActor : ReceiveActor { private readonly IServiceScope _scope; private readonly IUserActorService _userActorService; public UserActor(IServiceProvider serviceProvider) { _scope = serviceProvider.CreateScope(); _userActorService = _scope.ServiceProvider.GetRequiredService<IUserActorService>(); Receive<CreateUserMessage>(message => { var user = message.User; _userActorService.Create(user); }); } } Program using (var serviceScope = host.Services.CreateScope()) { var actorSystem = serviceScope.ServiceProvider.GetService<ActorSystem>(); var userActorService = serviceScope.ServiceProvider.GetRequiredService<IUserActorService>(); var userActor = actorSystem.ActorOf(Props.Create(() => new UserActor(userActorService)), "userActor"); var createUserMessage = new CreateUserMessage(new User() { Name = "Pedro Avila", Age = 46 }); userActor.Tell(createUserMessage); } The error I get is that an actor cannot be created with new
6 Replies
JakenVeina
JakenVeina2y ago
what actor?
pedroavila
pedroavilaOP2y ago
Akka.net uses actors
JakenVeina
JakenVeina2y ago
okay what actor gives you that error? where/when do you encounter that error? who/what is throwing that error?
pedroavila
pedroavilaOP2y ago
It occurs when I run the console app var userActorService = serviceScope.ServiceProvider.GetRequiredService<IUserActorService> This line gives error
JakenVeina
JakenVeina2y ago
what's IUserActorService? you got a registration for that?
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server