User: xtoff
Date: 2010/01/01 03:08 PM

Added:
 /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/
  ConfigFixture.cs
 /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/
  WcfConfigComponentLoader.cs

Modified:
 /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/
  Castle.Facilities.WcfIntegration.Tests-vs2008.csproj
 /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/
  Castle.Facilities.WcfIntegration-vs2008.csproj, WcfEndpoint.cs, WcfFacility.cs

Log:
 - added support for pulling client side WCF proxies information from WCF 
config file, without registering it with the container upfront

File Changes:

Directory: /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/
======================================================================

File [modified]: Castle.Facilities.WcfIntegration-vs2008.csproj
Delta lines: +39 -0
===================================================================

--- 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfConfigComponentLoader.cs
                               (rev 0)
+++ 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfConfigComponentLoader.cs
       2010-01-01 22:08:09 UTC (rev 6552)
@@ -0,0 +1,39 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.WcfIntegration
+{
+       using System;
+       using System.ServiceModel;
+
+       using Castle.MicroKernel.Registration;
+       using Castle.MicroKernel.Resolvers;
+
+       public class WcfConfigComponentLoader : ILazyComponentLoader
+       {
+               public IRegistration Load(string key, Type service)
+               {
+                       if (!Attribute.IsDefined(service, 
typeof(ServiceContractAttribute)))
+                       {
+                               return null;
+                       }
+
+                       //we assume the service is defined in the config file
+                       return Component.For(service)
+                               .Named(key)
+                               .LifeStyle.Transient
+                               .ActAs(new 
DefaultClientModel(WcfEndpoint.FromConfiguration(key)));
+               }
+       }
+}

File [added]: WcfConfigComponentLoader.cs
Delta lines: +4 -3
===================================================================

--- Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfEndpoint.cs    
2010-01-01 16:36:07 UTC (rev 6551)
+++ Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfEndpoint.cs    
2010-01-01 22:08:09 UTC (rev 6552)
@@ -14,11 +14,12 @@
 
 namespace Castle.Facilities.WcfIntegration
 {
-    using System;
+       using System;
        using System.Collections.Generic;
-    using System.ServiceModel;
-    using System.ServiceModel.Channels;
+       using System.ServiceModel;
+       using System.ServiceModel.Channels;
        using System.ServiceModel.Description;
+
        using Castle.Facilities.WcfIntegration.Behaviors;
 

File [modified]: WcfEndpoint.cs
Delta lines: +3 -1
===================================================================

--- Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfFacility.cs    
2010-01-01 16:36:07 UTC (rev 6551)
+++ Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration/WcfFacility.cs    
2010-01-01 22:08:09 UTC (rev 6552)
@@ -20,6 +20,7 @@
        using Castle.Core;
        using Castle.MicroKernel.Facilities;
        using Castle.MicroKernel.Registration;
+       using Castle.MicroKernel.Resolvers;
 
        /// <summary>
        /// Facility to simplify the management of WCF clients and services. 
@@ -42,7 +43,8 @@
 
                        Kernel.Register(
                                
Component.For<WcfClientExtension>().Instance(clientExtension),
-                               
Component.For<WcfServiceExtension>().Instance(serviceExtension)
+                               
Component.For<WcfServiceExtension>().Instance(serviceExtension),
+                               
Component.For<ILazyComponentLoader>().ImplementedBy<WcfConfigComponentLoader>()
                                );
 

File [modified]: WcfFacility.cs
Delta lines: +1 -0
===================================================================

--- 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests-vs2008.csproj
        2010-01-01 16:36:07 UTC (rev 6551)
+++ 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/Castle.Facilities.WcfIntegration.Tests-vs2008.csproj
        2010-01-01 22:08:09 UTC (rev 6552)
@@ -126,6 +126,7 @@
     <Compile Include="Components\IServiceWithDependencies.cs" />
     <Compile Include="Components\ServiceWithDependencies.cs" />
     <Compile Include="Components\TraceInterceptor.cs" />
+    <Compile Include="ConfigFixture.cs" />
     <Compile Include="Duplex\DuplexClientFixture.cs" />
     <Compile Include="Components\IOne.cs" />

Directory: /Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/
============================================================================

File [modified]: Castle.Facilities.WcfIntegration.Tests-vs2008.csproj
Delta lines: +109 -0
===================================================================

--- 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/ConfigFixture.cs
                            (rev 0)
+++ 
Facilities/Wcf/trunk/src/Castle.Facilities.WcfIntegration.Tests/ConfigFixture.cs
    2010-01-01 22:08:09 UTC (rev 6552)
@@ -0,0 +1,109 @@
+// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// 
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+// 
+//     http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace Castle.Facilities.WcfIntegration.Tests
+{
+       using System;
+       using System.Reflection;
+       using System.ServiceModel;
+       using System.ServiceModel.Description;
+
+       using Castle.Facilities.WcfIntegration.Demo;
+       using Castle.Facilities.WcfIntegration.Tests.Behaviors;
+       using Castle.MicroKernel.Registration;
+       using Castle.Windsor;
+
+       using NUnit.Framework;
+
+       [TestFixture]
+       public class ConfigFixture
+       {
+               private WindsorContainer container;
+
+               [SetUp]
+               public void SetUp()
+               {
+                       container = new WindsorContainer();
+                       container.AddFacility<WcfFacility>(f => f.CloseTimeout 
= TimeSpan.Zero);
+               }
+
+               [TearDown]
+               public void TearDown()
+               {
+                       container.Dispose();
+               }
+
+               [Test]
+               public void 
Can_resolve_component_based_solely_on_standard_wcf_config()
+               {
+                       var client = 
container.Resolve<IAmUsingWindsor>("WSHttpBinding_IAmUsingWindsor");
+                       Assert.IsInstanceOf<IClientChannel>(client);
+               }
+
+               [Test]
+               public void 
Can_use_component_based_solely_on_standard_wcf_config()
+               {
+                       container.Register(
+                               Component.For<IServiceBehavior>()
+                                       .Instance(new ServiceDebugBehavior()
+                                       {
+                                               IncludeExceptionDetailInFaults 
= true
+                                       }),
+                               Component.For<NetDataContractFormatBehavior>()
+                                       
.Attribute("scope").Eq(WcfExtensionScope.Explicit),
+                               
Component.For<IAmUsingWindsor>().ImplementedBy<UsingWindsor>()
+                                       .DependsOn(new { number = 42 })
+                                       .ActAs(new DefaultServiceModel()
+                                       )
+                               );
+
+
+                       var client = 
container.Resolve<IAmUsingWindsor>("WSHttpBinding_IAmUsingWindsor");
+                       var valueFromWindsorConfig = 
client.GetValueFromWindsorConfig();
+                       Assert.AreEqual(42, valueFromWindsorConfig);
+               }
+
+               [Test]
+               public void 
Can_call_asynchronousely_component_based_solely_on_standard_wcf_config()
+               {
+                       container.Register(
+                               Component.For<IServiceBehavior>()
+                                       .Instance(new ServiceDebugBehavior()
+                                       {
+                                               IncludeExceptionDetailInFaults 
= true
+                                       }),
+                               Component.For<NetDataContractFormatBehavior>()
+                                       
.Attribute("scope").Eq(WcfExtensionScope.Explicit),
+                               
Component.For<IAmUsingWindsor>().ImplementedBy<UsingWindsor>()
+                                       .DependsOn(new { number = 42 })
+                                       .ActAs(new DefaultServiceModel()
+                                       )
+                               );
+
+
+                       var client = 
container.Resolve<IAmUsingWindsor>("WSHttpBinding_IAmUsingWindsor");
+                       var asyncCall = client.BeginWcfCall(c => 
c.GetValueFromWindsorConfig());
+                       var valueFromWindsorConfig = asyncCall.End();
+                       Assert.AreEqual(42, valueFromWindsorConfig);
+               }
+
+               [Test]
+               public void 
Resolving_service_with_invalid_name_causes_exception()
+               {
+                       Assert.Throws(typeof(TargetInvocationException),
+                                     () => 
container.Resolve<IAmUsingWindsor>("NoSuchValueInConfig"));
+
+               }
+       }
+}

File [added]: ConfigFixture.cs
Delta lines: +0 -0
===================================================================

--

You received this message because you are subscribed to the Google Groups 
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-commits?hl=en.


Reply via email to