First, you can control whether a WCF service object is instantiated
once per call, once per WCF session, etc. by using the ServiceBehavior
attribute. For example, we use a per-call instance (a new instance of
our service object is instantiated for each call):
[ServiceContract]
[ServiceBehavior(InstanceContextMode =
InstanceContextMode.PerCall)]
public class MyService : IMyService
...
Second, though, we're using Unity and ServiceLocator. Our no-arg
constructors on our service call to our multi-arg constructors passing
values looked up using ServiceLocator...
public MyService ()
:this(ServiceLocator.Current.GetInstance<IUserTokenFactory>())
{}
public MyService (IUserTokenFactory userTokenFactory)
{
this._userTokenFactory = userTokenFactory;
}
Using this approach, you can register your SessionContextFactory once
in Unity and whenever WCF instantiates your services, your own no-arg
constructor will look up the dependencies for your service using the
ServiceLocator. So SessionFactory can just be one of those things
looked up and passed in.
It's not THE way, but it is A way.
Regards,
Brian.