public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            if (serviceDescription == null) {
                throw new ArgumentNullException("serviceDescription");
            }

            if (serviceHostBase == null) {
                throw new ArgumentNullException("serviceHostBase");
            }

            IEnumerable<string> source = serviceDescription.Endpoints.Where<ServiceEndpoint>(delegate(ServiceEndpoint ep) {
                return ep.Contract.ContractType.IsAssignableFrom(this._implementationType);
            }).Select<ServiceEndpoint, string>(delegate(ServiceEndpoint ep) {
                return ep.Contract.Name;
            });

            CoeveryInstanceProvider provider = new CoeveryInstanceProvider(this._workContextAccessor, this._componentRegistration);
            foreach (ChannelDispatcherBase base2 in serviceHostBase.ChannelDispatchers) {
                ChannelDispatcher dispatcher = base2 as ChannelDispatcher;
                if (dispatcher != null) {
                    foreach (EndpointDispatcher dispatcher2 in dispatcher.Endpoints) {
                        if (source.Contains<string>(dispatcher2.ContractName)) {
                            dispatcher2.DispatchRuntime.InstanceProvider = provider;
                        }
                    }
                    continue;
                }
            }
        }
Esempio n. 2
0
        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            if (serviceDescription == null)
            {
                throw new ArgumentNullException("serviceDescription");
            }

            if (serviceHostBase == null)
            {
                throw new ArgumentNullException("serviceHostBase");
            }

            IEnumerable <string> source = serviceDescription.Endpoints.Where <ServiceEndpoint>(delegate(ServiceEndpoint ep) {
                return(ep.Contract.ContractType.IsAssignableFrom(this._implementationType));
            }).Select <ServiceEndpoint, string>(delegate(ServiceEndpoint ep) {
                return(ep.Contract.Name);
            });

            CoeveryInstanceProvider provider = new CoeveryInstanceProvider(this._workContextAccessor, this._componentRegistration);

            foreach (ChannelDispatcherBase base2 in serviceHostBase.ChannelDispatchers)
            {
                ChannelDispatcher dispatcher = base2 as ChannelDispatcher;
                if (dispatcher != null)
                {
                    foreach (EndpointDispatcher dispatcher2 in dispatcher.Endpoints)
                    {
                        if (source.Contains <string>(dispatcher2.ContractName))
                        {
                            dispatcher2.DispatchRuntime.InstanceProvider = provider;
                        }
                    }
                    continue;
                }
            }
        }