0

I have a wcf application where I would like to resolve a service (TenantService) and setup some values. And I would like that service values to be used anywhere I inject that interface. I already configured autofac and it's working great.

I've registered my service as InstancePerLifeTimeScope

builder.RegisterType<TenantService>().AsImplementedInterfaces().InstancePerLifetimeScope();

Now I have a method in the TenantService that takes an Id and setup some stuff but whenever I inject the ITenantService in my Service.svc.cs file, I get a new instance that has nothing set.

So I like something that remains throughout the request scope just like owin middleware.

I tried creating custom ServiceHostFactory and setup ITenantService there by resolving it through AutofacHostFactory.Container but that didn't help. I also tried creating MessageInspector and called it through ServiceBehavior but the behavior created only once and in my Service.svs.cs file I still get a new instance of TenantService.

I think if I can set up my service with the OperationContext somehow then it might help but I am unsure how to do that. Any help?

Ask
  • 3,076
  • 6
  • 30
  • 63
  • This reads _almost_ the same as the original question, just rephrased. It seems like you should update/rephrase the original instead of starting a new question. – Travis Illig Oct 25 '22 at 02:02
  • @TravisIllig, that was autofac specific. But one is more of WCF specific. Both questions are still valid for me – Ask Oct 25 '22 at 06:12
  • If this one was WCF specific it shouldn't involve Autofac. They may seem very different to you, but from the outside perspective they are nigh identical, hence - it would be better to get all the info into one question with all the context; or rephrase this question to be more substantially different. – Travis Illig Oct 25 '22 at 12:42

0 Answers0