Use explicit interface implementation to be able to update the contract.
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / WindsorDependencyInjectionServiceBehavior.cs
blob44a387cc33258c8bacfd5dda1ad15eeb33d3c562
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 using Castle.MicroKernel;
17 namespace Castle.Facilities.WcfIntegration
19 using System;
20 using System.Collections.Generic;
21 using System.Collections.ObjectModel;
22 using System.ServiceModel;
23 using System.ServiceModel.Channels;
24 using System.ServiceModel.Description;
25 using System.ServiceModel.Dispatcher;
27 public class WindsorDependencyInjectionServiceBehavior : IServiceBehavior
29 private readonly IKernel kernel;
31 public WindsorDependencyInjectionServiceBehavior(IKernel kernel)
33 this.kernel = kernel;
36 #region IServiceBehavior Members
38 ///<summary>
39 ///Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
40 ///</summary>
41 ///<param name="serviceHostBase">The service host that is currently being constructed.</param>
42 ///<param name="serviceDescription">The service description.</param>
43 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
47 ///<summary>
48 ///Provides the ability to pass custom data to binding elements to support the contract implementation.
49 ///</summary>
50 ///<param name="serviceHostBase">The host of the service.</param>
51 ///<param name="bindingParameters">Custom objects to which binding elements have access.</param>
52 ///<param name="serviceDescription">The service description of the service.</param>
53 ///<param name="endpoints">The service endpoints.</param>
54 public void AddBindingParameters(
55 ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
56 Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
60 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
62 Dictionary<string, Type> contractNameToContractType = new Dictionary<string, Type>();
63 foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
65 contractNameToContractType[endpoint.Contract.Name] = endpoint.Contract.ContractType;
67 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
69 ChannelDispatcher cd = cdb as ChannelDispatcher;
70 if (cd != null)
72 foreach (EndpointDispatcher ed in cd.Endpoints)
74 if (contractNameToContractType.ContainsKey(ed.ContractName))
76 ed.DispatchRuntime.InstanceProvider =
77 new WindsorInstanceProvider(kernel,
78 contractNameToContractType[ed.ContractName],
79 serviceDescription.ServiceType
87 #endregion