I have a WCF service with ServiceBehavior.InstanceContextMode = InstanceContextMode.PerSession.
How do I need to register the service with Autofac to get a new instance for each new session but use the same instance in the session?
I am currently using the following configuration and it leads to behavior like PerCall:
builder.Register(c => new ChannelFactory<IUserService>()).SingleInstance();
builder.Register(c => c.Resolve<ChannelFactory<IUserService>>().CreateChannel())
.UseWcfSafeRelease();
builder.RegisterType<UserService>().AsImplementedInterfaces();
As we found out during the comments you were using basicHttpBinding. basicHttpBinding doesn’t support
ServiceBehavior.InstanceContextMode = InstanceContextMode.PerSessionSession Behaviour. For more details on bindings, check the MSDN DocumentationWhat I also like to add is that WCF automaticly keeps track of its session an if you close the proxy and reopen again you will get the same session. (If your binding of course supports it). Only when the client is closed your session will be terminate automaticly in WCF.