-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
Version Information
Version of Akka.NET? v1.4.34
Which Akka.NET Modules? Akka
Describe the bug
Discovered this while using Akka.Hosting.
Suppose you create multiple Setup
classes of discrete types:
Akka.DependencyInjection.DependencyResolverSetup
andAkka.Serialization.Hyperion.HyperionSerializerSetup
Right now Akka.NET only allows one setup of each type to be passed into the ActorSystem
, by way of an ActorSystemSetup
- which you can think of as an "aggregate" setup.
// earlier in the class
private readonly HashSet<Setup> _setups = new HashSet<Setup>();
var diSetup = DependencyResolverSetup.Create(sp);
var bootstrapSetup = BootstrapSetup.Create().WithConfig(Configuration.GetOrElse(Config.Empty));
if (ActorRefProvider.HasValue) // only set the provider when explicitly required
{
bootstrapSetup = bootstrapSetup.WithActorRefProvider(ActorRefProvider.Value);
}
var actorSystemSetup = bootstrapSetup.And(diSetup);
foreach (var setup in _setups)
{
actorSystemSetup = actorSystemSetup.And(setup);
}
WithSetup
is called byAnd
Because each individual Setup
is downcast to its base class (Setup
), the key that ActorSystemSetup.And
is going to use to store each of the Setup
s inside _setups
is.... Setup
- therefore, the contents of _setups
all override each other and only the last Setup
in the set actually gets used inside the ActorSystemSetup
.
Expected behavior
What should happen instead is that the type key of the actual concrete type should be included, rather than the generic parameter argument:
akka.net/src/core/Akka/Actor/Setup/ActorSystemSetup.cs
Lines 73 to 76 in 21762b9
public ActorSystemSetup WithSetup<T>(T setup) where T : Setup | |
{ | |
return new ActorSystemSetup(_setups.SetItem(typeof(T), setup)); | |
} |
Rather than do typeof(T)
we should probably do setup.GetType()
in order to ensure that this type collision does not occur.
Actual behavior
What actually happened and how did it differ from your expectations?
All Setup
s included in a collection of Setup
types overrode each other.