Autofac.ServiceFabric icon indicating copy to clipboard operation
Autofac.ServiceFabric copied to clipboard

Singleton does not play nicely with ServiceContext dependency

Open MattHartz opened this issue 5 years ago • 1 comments

Hi,

I just recently added a logger into my service fabric application to log all service fabric communication. Because of this, it is dependent on ServiceContext. When I register my type that is dependent (on something that is dependent on something) on ServiceContext as a SingleInstance, when the Service resolve's said type I get "The requested service 'System.Fabric.ServiceContext' has not been registered".

If i remove "SingleInstance()" from the registration, everything works business as usual. Now, making my service not a singleton, isn't the worst thing in the world, but i would love for it to function as a Singleton.

I've tried injecting it as a "Lazy<T>", and a Func<Lazy<T>>, and all result in the same error. Any ideas?

Autofac.ServiceFabric 2.2.0 ServiceFabric 3.4.641

Stack trace: at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable1 parameters) at Fake.ApplicationInsights.Autofac.RegistrationExtension.<>c__DisplayClass1_01.<RegisterFakeApplicationInsights>b__1(IComponentContext c) in C:\Users\matth\Documents\Fake Code\FakeShared\Fake.ApplicationInsights\Source\Fake.ApplicationInsights\Autofac\RegistrationExtension.cs:line 59 at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass0_01.<ForDelegate>b__0(IComponentContext c, IEnumerable1 p) at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)

Thanks!

MattHartz avatar Sep 24 '19 20:09 MattHartz

Same issue. Any updates?

balbelias avatar Apr 20 '21 12:04 balbelias