/// <summary> /// Provides the ability to change run-time property values or insert custom extension objects such as error handlers, message or parameter interceptors, security extensions, and other custom extension objects. /// </summary> /// <param name="serviceDescription">The service description.</param> /// <param name="serviceHostBase">The host that is currently being built.</param> /// <exception cref="ArgumentNullException"> /// Thrown if <paramref name="serviceDescription" /> or /// <paramref name="serviceHostBase" /> is <see langword="null" />. /// </exception> public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) { if (serviceDescription == null) { throw new ArgumentNullException(nameof(serviceDescription)); } if (serviceHostBase == null) { throw new ArgumentNullException(nameof(serviceHostBase)); } var instanceProvider = new ServiceProviderInstanceProvider(serviceProvider, new ServiceFactory(serviceContract).CreateInstance); var serviceEndpointContractNames = serviceDescription.GetContractNames(serviceContract).ToArray(); foreach (var endpointDispatcher in serviceHostBase.GetEndpointDispatchers(serviceEndpointContractNames)) { endpointDispatcher.DispatchRuntime.InstanceProvider = instanceProvider; } }