1
// Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
18 using System
.ServiceModel
;
19 using System
.ServiceModel
.Channels
;
20 using System
.ServiceModel
.Dispatcher
;
24 /// Initialize a service using Windsor
26 public class WindsorInstanceProvider
: IInstanceProvider
28 private readonly IWindsorContainer container
;
29 private readonly Type type
;
32 /// Initializes a new instance of the <see cref="WindsorInstanceProvider"/> class.
34 public WindsorInstanceProvider(IWindsorContainer container
, Type type
)
36 this.container
= container
;
40 #region IInstanceProvider Members
43 ///Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"></see> object.
47 ///A user-defined service object.
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);
57 ///Returns a service object given the specified <see cref="T:System.ServiceModel.InstanceContext"></see> object.
61 ///The service object.
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
);
72 ///Called when an <see cref="T:System.ServiceModel.InstanceContext"></see> object recycles a service object.
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
);