autofac / Autofac.ServiceFabric

Autofac integration for Azure Service Fabric. Provides service factory implementations for Actors, Stateful Services and Stateless Services.
MIT License
26 stars 27 forks source link

Cannot resolve parameter 'System.Fabric.StatefulServiceContext serviceContext' #50

Closed inge-j closed 5 years ago

inge-j commented 5 years ago

Hi, I am trying to register the ReliableStateManager in the container. The constructor requires StatefulServiceContext and a ReliableStateManagerConfiguration object. No matter how I try registering it I end up with the following exception:

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Microsoft.ServiceFabric.Data.ReliableStateManager' can be invoked with the available services and parameters: Cannot resolve parameter 'System.Fabric.StatefulServiceContext serviceContext' of constructor 'Void .ctor(System.Fabric.StatefulServiceContext, Microsoft.ServiceFabric.Data.ReliableStateManagerConfiguration)'.

I have tried registering the state manager like this:

builder.Register(c => new ReliableStateManager(c.Resolve<StatefulServiceContext>(), null)).As<IReliableStateManager>().SingleInstance();

and

builder.RegisterType<ReliableStateManager>().As<IReliableStateManager>().WithParameter("configuration", null).SingleInstance();

before calling

builder.RegisterStatefulService<TService>(serviceType);

Before using the Autofac.ServiceFabric 2.2.0 package, we wired everything up manually, meaning registering the context and state manager in the container and it was working as expected.

I see that the StatefulServiceContext is registered just before the service is resolved. It this a timing issue maybe?

MattHartz commented 5 years ago

Hi @inge-j , I noticed you are using SingleInstance, which is also giving me grief. Did you solve this?

inge-j commented 5 years ago

Hi, no, I did not figure it out unfortunately :/