Applying code formatting + license header
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / WindsorDependencyInjectionServiceBehavior.cs
blob869210c79026784b78443118d26597998ca64a47
1 // Copyright 2004-2007 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 Windsor;
26 public class WindsorDependencyInjectionServiceBehavior : IServiceBehavior
28 private readonly IWindsorContainer container;
30 public WindsorDependencyInjectionServiceBehavior(IWindsorContainer container)
32 this.container = container;
35 #region IServiceBehavior Members
37 ///<summary>
38 ///Provides the ability to inspect the service host and the service description to confirm that the service can run successfully.
39 ///</summary>
40 ///<param name="serviceHostBase">The service host that is currently being constructed.</param>
41 ///<param name="serviceDescription">The service description.</param>
42 public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
46 ///<summary>
47 ///Provides the ability to pass custom data to binding elements to support the contract implementation.
48 ///</summary>
49 ///<param name="serviceHostBase">The host of the service.</param>
50 ///<param name="bindingParameters">Custom objects to which binding elements have access.</param>
51 ///<param name="serviceDescription">The service description of the service.</param>
52 ///<param name="endpoints">The service endpoints.</param>
53 public void AddBindingParameters(
54 ServiceDescription serviceDescription, ServiceHostBase serviceHostBase,
55 Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
59 public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
61 Dictionary<string, Type> contractNameToContractType = new Dictionary<string, Type>();
62 foreach (ServiceEndpoint endpoint in serviceDescription.Endpoints)
64 contractNameToContractType[endpoint.Contract.Name] = endpoint.Contract.ContractType;
66 foreach (ChannelDispatcherBase cdb in serviceHostBase.ChannelDispatchers)
68 ChannelDispatcher cd = cdb as ChannelDispatcher;
69 if (cd != null)
71 foreach (EndpointDispatcher ed in cd.Endpoints)
73 if (contractNameToContractType.ContainsKey(ed.ContractName))
75 ed.DispatchRuntime.InstanceProvider =
76 new WindsorInstanceProvider(container,
77 contractNameToContractType[ed.ContractName]
85 #endregion