public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { serviceDescription.ThrowOnNull("serviceDescription"); serviceHostBase.ThrowOnNull("serviceHostBase"); var sb = serviceDescription.Behaviors.Find <ServiceBehaviorAttribute>(); foreach (var ed in serviceHostBase.ChannelDispatchers.OfType <ChannelDispatcher>().SelectMany(cd => cd.Endpoints)) { if (sb != null && sb.InstanceContextMode == InstanceContextMode.Single) { ed.DispatchRuntime.SingletonInstanceContext = new InstanceContext(serviceHostBase); } ed.DispatchRuntime.InstanceProvider = new OrganizationServiceCacheServiceInstanceProvider(_cache); } }