1 // Copyright 2004-2008 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
19 using Castle
.MicroKernel
;
20 using Castle
.MicroKernel
.ComponentActivator
;
22 public class WcfClientActivator
: DefaultComponentActivator
24 private readonly ChannelCreator createChannel
;
26 public WcfClientActivator(ComponentModel model
, IKernel kernel
,
27 ComponentInstanceDelegate onCreation
, ComponentInstanceDelegate onDestruction
)
28 : base(model
, kernel
, onCreation
, onDestruction
)
30 createChannel
= CreateChannelCreator(kernel
, model
);
33 protected override object InternalCreate(CreationContext context
)
35 object instance
= Instantiate(context
);
37 ApplyCommissionConcerns(instance
);
42 protected override object Instantiate(CreationContext context
)
44 object instance
= createChannel();
48 instance
= Kernel
.ProxyFactory
.Create(Kernel
, instance
, Model
);
52 throw new ComponentActivatorException("WcfClientActivator: could not proxy service " +
53 Model
.Service
.FullName
, ex
);
59 private ChannelCreator
CreateChannelCreator(IKernel kernel
, ComponentModel model
)
61 WcfClientModel clientModel
= (WcfClientModel
)
62 model
.ExtendedProperties
[WcfConstants
.ClientModelKey
];
64 IClientChannelBuilder channelBuilder
= kernel
.Resolve
<IClientChannelBuilder
>();
65 ChannelCreator creator
= channelBuilder
.GetChannelCreator(clientModel
.Endpoint
, model
.Service
);
66 model
.ExtendedProperties
[WcfConstants
.ChannelCreatorKey
] = creator
;