Skip to content

DependencyResolver invokes the wrong constructor #5554

@fscavo

Description

@fscavo

Version Information
Version of Akka.NET? 1.4.32
Which Akka.NET Modules?
Akka.Cluster
Akka.Cluster.Sharding

I have an actor with the following constructors defined in this order:

public IdMappingUpsertionWorkflowActor(EventWorkflowOptions options) : base(options) { }
public IdMappingUpsertionWorkflowActor() : this(new EventWorkflowOptions { TerminateOnFailed = false, TerminateOnCompleted = false }) { }

And this is how I create the actor:

var props = DependencyResolver.For(context.System).Props<TWorkflow>(args);
return context.ActorOf(props, $"{typeof(TWorkflow).Name.ToKebabCase()}-{Guid.NewGuid():N}");

DependencyResolver tries to invoke the first constructor (with parameters), though args is empty. If I change the order of constructors definition to be like the following, it works:

public IdMappingUpsertionWorkflowActor() : this(new EventWorkflowOptions { TerminateOnFailed = false, TerminateOnCompleted = false }) { }
public IdMappingUpsertionWorkflowActor(EventWorkflowOptions options) : base(options) { }

This is the exception that throws during actor creation:

[Akka.Actor.OneForOneStrategy] Error while creating actor instance of type Agrifirm.Service.BusinessPartnerAggregation.IdMapping.IdMappingUpsertionWorkflowActor with 0 args: ()
[akka://business-partner-aggregation-service/system/sharding/customer-orchestrator/0/1-01-202201310703037753/id-mapping-upsertion-workflow-actor-b3bb4da4ff154c89a64280fb7ed11943#95192911]: Akka.Actor.ActorInitializationException: Exception during creation
 ---> System.TypeLoadException: Error while creating actor instance of type Agrifirm.Service.BusinessPartnerAggregation.IdMapping.IdMappingUpsertionWorkflowActor with 0 args: ()
 ---> System.InvalidOperationException: Unable to resolve service for type 'Agrifirm.Core.BuildingBlocks.Workflows.EventWorkflowOptions' while attempting to activate 'Agrifirm.Service.BusinessPartnerAggregation.IdMapping.IdMappingUpsertionWorkflowActor'.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Akka.DependencyInjection.ServiceProviderActorProducer.Produce()
   at Akka.Actor.Props.NewActor()
   --- End of inner exception stack trace ---
   at Akka.Actor.Props.NewActor()
   at Akka.Actor.ActorCell.CreateNewActorInstance()
   at Akka.Actor.ActorCell.<>c__DisplayClass116_0.<NewActor>b__0()
   at Akka.Actor.ActorCell.UseThreadContext(Action action)
   at Akka.Actor.ActorCell.NewActor()
   at Akka.Actor.ActorCell.Create(Exception failure)
   --- End of inner exception stack trace ---
   at Akka.Actor.ActorCell.Create(Exception failure)
   at Akka.Actor.ActorCell.FinishCreate()

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions