User: xtoff
Date: 2009/12/15 02:59 PM

Added:
 /InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/
  ICommon2.cs, TwoInterfacesImpl.cs
 /InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/
  ConfigurationForwardedTypesTestCase.cs, config_with_forwarded_types.xml

Modified:
 /InversionOfControl/trunk/src/Castle.MicroKernel.Tests/
  Castle.MicroKernel.Tests-vs2008.csproj
 /InversionOfControl/trunk/src/Castle.Windsor.Tests/
  Castle.Windsor.Tests-vs2008.csproj
 /InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/
  synchtest_config.xml
 /InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/
  AbstractInterpreter.cs, XmlInterpreter.cs
 /InversionOfControl/trunk/src/Castle.Windsor/Installer/
  DefaultComponentInstaller.cs

Log:
 - added support for forwarded types in the config. The syntax is the following:
 <component
        id="hasForwards"
        type="Castle.MicroKernel.Tests.ClassComponents.TwoInterfacesImpl, 
Castle.MicroKernel.Tests"
        service="Castle.MicroKernel.Tests.ClassComponents.ICommon, 
Castle.MicroKernel.Tests">
        <forward
                service="Castle.MicroKernel.Tests.ClassComponents.ICommon2, 
Castle.MicroKernel.Tests" />
 </component>
 
 there can be obvioulsy multiple 'forward' elements

File Changes:

Directory: /InversionOfControl/trunk/src/Castle.MicroKernel.Tests/
==================================================================

File [modified]: Castle.MicroKernel.Tests-vs2008.csproj
Delta lines: +18 -0
===================================================================

--- 
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/ICommon2.cs
                           (rev 0)
+++ 
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/ICommon2.cs
   2009-12-15 21:59:55 UTC (rev 6431)
@@ -0,0 +1,18 @@
+// 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.MicroKernel.Tests.ClassComponents
+{
+       public interface ICommon2 { }
+}

Directory: /InversionOfControl/trunk/src/Castle.Windsor.Tests/
==============================================================

File [modified]: Castle.Windsor.Tests-vs2008.csproj
Delta lines: +34 -0
===================================================================

--- 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/ConfigurationForwardedTypesTestCase.cs
                             (rev 0)
+++ 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/ConfigurationForwardedTypesTestCase.cs
     2009-12-15 21:59:55 UTC (rev 6431)
@@ -0,0 +1,34 @@
+namespace Castle.Windsor.Tests.Configuration2
+{
+       using System;
+       using System.IO;
+
+       using Castle.MicroKernel.Tests;
+       using Castle.MicroKernel.Tests.ClassComponents;
+
+       using NUnit.Framework;
+
+       [TestFixture]
+       public class ConfigurationForwardedTypesTestCase
+       {
+
+               [SetUp]
+               public void SetUp()
+               {
+
+                       var dir = 
ConfigHelper.ResolveConfigPath("Configuration2/");
+                       var file = 
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, dir + 
"config_with_forwarded_types.xml");
+                       container = new WindsorContainer(file);
+               }
+
+               private IWindsorContainer container;
+
+               [Test]
+               public void Component_with_forwarded_types()
+               {
+                       var first = container.Resolve<ICommon>("hasForwards");
+                       var second = container.Resolve<ICommon2>();
+                       Assert.AreSame(first, second);
+               }
+       }
+}

Directory: 
/InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/
==================================================================================

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

--- 
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/TwoInterfacesImpl.cs
                          (rev 0)
+++ 
InversionOfControl/trunk/src/Castle.MicroKernel.Tests/ClassComponents/TwoInterfacesImpl.cs
  2009-12-15 21:59:55 UTC (rev 6431)
@@ -0,0 +1,20 @@
+// 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.MicroKernel.Tests.ClassComponents
+{
+       public class TwoInterfacesImpl : ICommon2, ICommon
+       {
+       }
+}

File [added]: TwoInterfacesImpl.cs
Delta lines: +1 -1
===================================================================

--- 
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/AbstractInterpreter.cs
       2009-12-15 18:42:27 UTC (rev 6430)
+++ 
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/AbstractInterpreter.cs
       2009-12-15 21:59:55 UTC (rev 6431)
@@ -38,7 +38,7 @@
                protected static readonly string BootstrapNodeName = 
"bootstrap";
                protected static readonly string ComponentNodeName = 
"component";
                protected static readonly string IncludeNodeName = "include";
-               protected static readonly string PropertiesNodeName = 
"properties";             
+               protected static readonly string PropertiesNodeName = 
"properties";
 
                // private ImportDirectiveCollection imports = new 
ImportDirectiveCollection();

Directory: /InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/
=============================================================================

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

--- 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/config_with_forwarded_types.xml
                            (rev 0)
+++ 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/config_with_forwarded_types.xml
    2009-12-15 21:59:55 UTC (rev 6431)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+       <components>
+               <component
+                       id="hasForwards"
+                       
type="Castle.MicroKernel.Tests.ClassComponents.TwoInterfacesImpl, 
Castle.MicroKernel.Tests"
+                       
service="Castle.MicroKernel.Tests.ClassComponents.ICommon, 
Castle.MicroKernel.Tests">
+                       <forward 
+                               
service="Castle.MicroKernel.Tests.ClassComponents.ICommon2, 
Castle.MicroKernel.Tests" />
+               </component>
+       </components>

File [added]: config_with_forwarded_types.xml
Delta lines: +1 -1
===================================================================

--- 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/synchtest_config.xml
       2009-12-15 18:42:27 UTC (rev 6430)
+++ 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Configuration2/synchtest_config.xml
       2009-12-15 21:59:55 UTC (rev 6431)
@@ -10,7 +10,7 @@
                                        <dictionary>
                                                <entry key="key1">value</entry>
                                        </dictionary>
-                               </dict>                         
+                               </dict>
                        </parameters>
                </component>

File [modified]: synchtest_config.xml
Delta lines: +0 -0
===================================================================

Directory: /InversionOfControl/trunk/src/Castle.Windsor/Installer/
==================================================================

File [modified]: DefaultComponentInstaller.cs
Delta lines: +2 -0
===================================================================

--- 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Castle.Windsor.Tests-vs2008.csproj
        2009-12-15 18:42:27 UTC (rev 6430)
+++ 
InversionOfControl/trunk/src/Castle.Windsor.Tests/Castle.Windsor.Tests-vs2008.csproj
        2009-12-15 21:59:55 UTC (rev 6431)
@@ -214,6 +214,7 @@
     <Compile Include="Components\SimpleMixIn.cs" />
     <Compile Include="ConfigHelper.cs" />
     <Compile Include="Configuration2\ConfigurationEnvTestCase.cs" />
+    <Compile Include="Configuration2\ConfigurationForwardedTypesTestCase.cs" />
     <Compile Include="Configuration2\ConfigWithStatementsTestCase.cs">
       <SubType>Code</SubType>
     </Compile>
@@ -376,6 +377,7 @@
     <None Include="DotNet2Config\chainOfRespnsability_smart.config" />
     <EmbeddedResource Include="Configuration2\env_config.xml" />
     <EmbeddedResource Include="Configuration2\eval_config.xml" />
+    <Content Include="Configuration2\config_with_forwarded_types.xml" />
     <Content Include="Configuration2\synchtest_config.xml" />
     <EmbeddedResource Include="sample_config_with_spaces.xml" />

Directory: 
/InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/
===================================================================================

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

--- 
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlInterpreter.cs
    2009-12-15 18:42:27 UTC (rev 6430)
+++ 
InversionOfControl/trunk/src/Castle.Windsor/Configuration/Interpreters/XmlInterpreter.cs
    2009-12-15 21:59:55 UTC (rev 6431)
@@ -98,7 +98,7 @@
                        {
                                XmlNode element = processor.Process(source);
 
-                               Deserialize(element, store);                    
        
+                               Deserialize(element, store);
                        }
                        catch(XmlProcessorException)

File [modified]: XmlInterpreter.cs
Delta lines: +24 -4
===================================================================

--- 
InversionOfControl/trunk/src/Castle.Windsor/Installer/DefaultComponentInstaller.cs
  2009-12-15 18:42:27 UTC (rev 6430)
+++ 
InversionOfControl/trunk/src/Castle.Windsor/Installer/DefaultComponentInstaller.cs
  2009-12-15 21:59:55 UTC (rev 6431)
@@ -15,6 +15,7 @@
 namespace Castle.Windsor.Installer
 {
        using System;
+       using System.Collections.Generic;
        using System.Configuration;
 
        using Castle.Core.Configuration;
@@ -70,13 +71,13 @@
                {
                        foreach(IConfiguration component in configurations)
                        {
-                               string id = component.Attributes["id"];
+                               var id = component.Attributes["id"];
                                
-                               string typeName = component.Attributes["type"];
-                               string serviceTypeName = 
component.Attributes["service"];
+                               var typeName = component.Attributes["type"];
+                               var serviceTypeName = 
component.Attributes["service"];
                                
                                if (string.IsNullOrEmpty(typeName)) continue;
-
+                               
                                Type type = ObtainType(typeName);
                                Type service = type;
 
@@ -85,12 +86,31 @@
                                        service = ObtainType(serviceTypeName);
                                }
 
+                               var forwarded = new List<Type>();
+                               foreach (var child in 
component.Children.FindAll(c => "forward".Equals(c.Name, 
StringComparison.OrdinalIgnoreCase)))
+                               {
+                                       var forwardedServiceTypeName = 
child.Attributes["service"];
+                                       try
+                                       {
+                                               
forwarded.Add(ObtainType(forwardedServiceTypeName));
+                                       }
+                                       catch (ConfigurationErrorsException e)
+                                       {
+                                               throw new 
ConfigurationErrorsException(
+                                                       
string.Format("Component {0}-{1} defines invalid forwarded type.", id ?? 
string.Empty, typeName), e);
+                                       }
+                               }
+
 #if DEBUG
                                System.Diagnostics.Debug.Assert( id != null );
                                System.Diagnostics.Debug.Assert( type != null );
                                System.Diagnostics.Debug.Assert( service != 
null );
 #endif
                                container.AddComponent(id, service, type);
+                               foreach (var forwadedType in forwarded)
+                               {
+                                       
container.Kernel.RegisterHandlerForwarding(forwadedType, id);
+                               }
                        }
                }

--

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