Applying code formatting + license header
[castle.git] / Facilities / Wcf / Castle.Facilities.WcfIntegration / WindsorInstanceProvider.cs
blob3c8e2b4e7bf66d4cd142c482499fdada95bcfe10
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.ServiceModel;
19 using System.ServiceModel.Channels;
20 using System.ServiceModel.Dispatcher;
21 using Windsor;
23 /// <summary>
24 /// Initialize a service using Windsor
25 /// </summary>
26 public class WindsorInstanceProvider : IInstanceProvider
28 private readonly IWindsorContainer container;
29 private readonly Type type;
31 /// <summary>
32 /// Initializes a new instance of the <see cref="WindsorInstanceProvider"/> class.
33 /// </summary>
34 public WindsorInstanceProvider(IWindsorContainer container, Type type)
36 this.container = container;
37 this.type = type;
40 #region IInstanceProvider Members
42 ///<summary>
43 ///Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"></see> object.
44 ///</summary>
45 ///
46 ///<returns>
47 ///A user-defined service object.
48 ///</returns>
49 ///
50 ///<param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"></see> object.</param>
51 public object GetInstance(InstanceContext instanceContext)
53 return GetInstance(instanceContext, null);
56 ///<summary>
57 ///Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"></see> object.
58 ///</summary>
59 ///
60 ///<returns>
61 ///The service object.
62 ///</returns>
63 ///
64 ///<param name="message">The message that triggered the creation of a service object.</param>
65 ///<param name="instanceContext">The current <see cref="T:System.ServiceModel.InstanceContext"></see> object.</param>
66 public object GetInstance(InstanceContext instanceContext, Message message)
68 return container.Resolve(type);
71 ///<summary>
72 ///Called when an <see cref="T:System.ServiceModel.InstanceContext"></see> object recycles a service object.
73 ///</summary>
74 ///
75 ///<param name="instanceContext">The service's instance context.</param>
76 ///<param name="instance">The service object to be recycled.</param>
77 public void ReleaseInstance(InstanceContext instanceContext, object instance)
79 container.Release(instance);
82 #endregion