pedroavila
pedroavila
CC#
Created by pedroavila on 4/30/2023 in #help
❔ 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
12 replies