❔ 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 new6 Replies
what actor?
Akka.net uses actors
okay
what actor gives you that error?
where/when do you encounter that error?
who/what is throwing that error?
It occurs when I run the console app
var userActorService = serviceScope.ServiceProvider.GetRequiredService<IUserActorService> This line gives error
what's
IUserActorService
?
you got a registration for that?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.