Little code cleanup. Since WCF creates TransparentProxy that implements IDisposable...
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / Service / WindsorServiceHost.cs
blobae8e88010eee19defc3aea747ba05cd879bc67c0
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.ServiceModel;
19 using System.ServiceModel.Description;
20 using MicroKernel;
21 using Windsor;
23 public class WindsorServiceHost : ServiceHost
25 private readonly IKernel kernel;
27 public WindsorServiceHost(IKernel kernel, Type serviceType, params Uri[] baseAddresses)
28 : base(serviceType, baseAddresses)
30 this.kernel = kernel;
33 protected override void OnOpening()
35 Description.Behaviors.Add(new WindsorDependencyInjectionServiceBehavior(kernel));
36 IHandler[] serviceBehaviorHandlers = kernel.GetHandlers(typeof (IServiceBehavior));
37 foreach (IHandler handler in serviceBehaviorHandlers)
39 Description.Behaviors.Add((IServiceBehavior) handler.Resolve(CreationContext.Empty));
41 IHandler[] endPointBehaviors = kernel.GetHandlers(typeof (IEndpointBehavior));
42 foreach (IHandler handler in endPointBehaviors)
44 foreach (ServiceEndpoint endpoint in Description.Endpoints)
46 endpoint.Behaviors.Add((IEndpointBehavior) handler.Resolve(CreationContext.Empty));
49 base.OnOpening();