Exemplo n.º 1
0
        /// <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>
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            var handlers = DependencyFactory.ResolveAll <IErrorHandler>().ToList();

            foreach (var dispatcherBase in serviceHostBase.ChannelDispatchers)
            {
                var channelDispatcher = dispatcherBase as ChannelDispatcher;

                if (channelDispatcher != null)
                {
                    foreach (var errorHandler in handlers)
                    {
                        channelDispatcher.ErrorHandlers.Add(errorHandler);
                    }

                    foreach (var ed in channelDispatcher.Endpoints)
                    {
                        ed.DispatchRuntime.InstanceProvider = new UnityInstanceProvider(serviceDescription.ServiceType);
                    }
                }
            }
        }