Fixing an issue with output parameters that are of type IntPtr
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / Service / WindsorDependencyInjectionServiceBehavior.cs
blob2f79ef69808e0de182bccde527aa87aad52dbd66
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 namespace Castle.Facilities.WcfIntegration
17 using System;
18 using System.Collections.Generic;
19 using System.Collections.ObjectModel;
20 using System.ServiceModel;
21 using System.ServiceModel.Channels;
22 using System.ServiceModel.Description;
23 using System.ServiceModel.Dispatcher;
24 using Castle.Core;
25 using Castle.MicroKernel;
27 public class WindsorDependencyInjectionServiceBehavior : IServiceBehavior
29 private readonly IKernel kernel;
30 private readonly ComponentModel model;
32 public WindsorDependencyInjectionServiceBehavior(IKernel kernel, ComponentModel model)
34 this.kernel = kernel;
35 this.model = model;
38 #region IServiceBehavior Members
40 ///<summary>
41 ///Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
42 ///</summary>
43 ///<param name="serviceHostBase">The service host that is currently being constructed.</param>
44 ///<param name="serviceDescription">The service description.</param>
45 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
49 ///<summary>
50 ///Provides the ability to pass custom data to binding elements to support the contract implementation.
51 ///</summary>
52 ///<param name="serviceHostBase">The host of the service.</param>
53 ///<param name="bindingParameters">Custom objects to which binding elements have access.</param>
54 ///<param name="serviceDescription">The service description of the service.</param>
55 ///<param name="endpoints">The service endpoints.</param>
56 public void AddBindingParameters(
57 ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
58 Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
62 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
64 Dictionary<string, Type> contractNameToContractType = new Dictionary<string, Type>();
65 foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
67 contractNameToContractType[endpoint.Contract.Name] = endpoint.Contract.ContractType;
69 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
71 ChannelDispatcher cd = cdb as ChannelDispatcher;
72 if (cd != null)
74 foreach (EndpointDispatcher ed in cd.Endpoints)
76 if (contractNameToContractType.ContainsKey(ed.ContractName))
78 ed.DispatchRuntime.InstanceProvider =
79 new WindsorInstanceProvider(kernel, model,
80 contractNameToContractType[ed.ContractName],
81 serviceDescription.ServiceType
89 #endregion