Skip to content

ActorSystemSetup.And forgets types #5728

@Aaronontheweb

Description

@Aaronontheweb

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:

  1. Akka.DependencyInjection.DependencyResolverSetup and
  2. Akka.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 by And

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 Setups 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:

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 Setups included in a collection of Setup types overrode each other.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions