Ask
Ask

Reputation: 3726

How to setup service in WCF that can be used anywhere within the request scope?

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?

Upvotes: 0

Views: 14

Answers (0)

Related Questions