akkadotnet / Akka.Hosting

Akka.Hosting - standardized Akka.NET hosting without any HOCON configuration. Ties into Microsoft.Extensions.Configuration, Logging, Hosting, and DependencyInjection.
Apache License 2.0
52 stars 13 forks source link

Support names as an alternative of types when registering an actor #443

Closed rlugmania closed 2 months ago

rlugmania commented 2 months ago

I am trying to register two actors from the same actor type using the WithActors Method, the current implementation based on types uses the name of the type for registering the actor, so that should be a good idea to implement a new method inside the IActorRegsitry interface that supports a string as a key instead of a type.

So the new method could be something like this:

bool TryRegister(string name, IActorRef actor, bool overwrite = false);

For getting the actor instance the interface could be something similar to the dotnet keyed services by using an annotation like

[FromActorsName("player")]IRequiredActor<MyActor> playerActor

Aaronontheweb commented 2 months ago

We intentionally do not want to support string because it'll lead to abuse of the ActorRegistry. Users should be putting aggregates (i.e. parents, ShardRegions) into there, not individual entity actors et al - using Type as the key helps enforce that good design (this is a "pit of success" design.)

FWIW, the actor's implementation type and the type key used in the ActorRegistry don't have to have any relationship to each other - it's arbitrary. So your requirement today is already supported.