From b7585340b9a7193b9e59ce03e6aa68d970fd92a7 Mon Sep 17 00:00:00 2001
From: ni-mi <51543420+ni-mi@users.noreply.github.com>
Date: Sun, 29 Nov 2020 18:21:59 +0200
Subject: [PATCH 1/5] Fix bug decribed in
https://github.com/castleproject/Windsor/issues/574 of Dictionaries with
referenced lists as values
---
.../Config/ConfigurationTestCase.cs | 61 +++++++++++++++++++
.../Conversion/GenericListConverter.cs | 5 ++
2 files changed, 66 insertions(+)
diff --git a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
index a81e7c7c93..6c84bd9c46 100644
--- a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
+++ b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
@@ -14,6 +14,8 @@
namespace Castle.MicroKernel.Tests.Configuration
{
+ using System.Collections.Generic;
+
using Castle.Core;
using Castle.Core.Configuration;
using Castle.Core.Resource;
@@ -33,6 +35,65 @@ namespace Castle.MicroKernel.Tests.Configuration
[TestFixture]
public class ConfigurationTestCase : AbstractContainerTestCase
{
+
+
+
+
+ [Test]
+ [Bug("https://github.com/castleproject/Windsor/issues/574")]
+ public void DictionaryWithReferencedList()
+ {
+ var config =
+ @"
+
+
+
+
+
+
+
+
+ - 11
+ - 12
+
+
+
+
+
+
+
+
+
+ - 21
+ - 22
+
+
+
+
+
+
+
+
+
+ ${list}
+ ${list2}
+
+
+
+
+
+";
+
+ Container.Install(Configuration.FromXml(new StaticContentResource(config)));
+ var stringsList = Container.Resolve>("list");
+ var stringToListDictionary = Container.Resolve>>("stringToListDictionary");
+ Assert.NotNull(stringToListDictionary);
+ Assert.AreEqual(2, stringToListDictionary.Count);
+ }
+
+
+
+
[Test]
[Bug("IOC-155")]
public void Type_not_implementing_service_should_throw()
diff --git a/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs b/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
index 58d1cf14e5..3dcf42b57a 100644
--- a/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
+++ b/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
@@ -42,6 +42,11 @@ public override bool CanHandleType(Type type)
public override object PerformConversion(String value, Type targetType)
{
+ if (value != null && value.Contains("${"))
+ {
+ String newValue = value.Replace("${", "").Replace("}", "");
+ return Context.Kernel.Resolve(newValue, targetType);
+ }
throw new NotImplementedException();
}
From cc1ed2a6238f4554014374203bfc54da7d012568 Mon Sep 17 00:00:00 2001
From: ni-mi <51543420+ni-mi@users.noreply.github.com>
Date: Sun, 29 Nov 2020 18:39:00 +0200
Subject: [PATCH 2/5] Add details to CHANGELOG.md
---
CHANGELOG.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 292fad9480..d461383db2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,7 @@
Bugfixes:
- Fix CollectionResolver to allow propagation of inline dependencies (@dvdwouwe, #562)
- Allow DefaultNamingSubSystem derivatives to invalidate the cache which was accidently removed in 5.1.0 (@nativenolde, #569)
+- Fix dictionary bug where reference to list components didn't work (@ni-mi, #575)
## 5.1.0 (2020-11-16)
From 7de8d5ed35c0ad4187294d71d8086fc492f00ddd Mon Sep 17 00:00:00 2001
From: ni-mi <51543420+ni-mi@users.noreply.github.com>
Date: Mon, 30 Nov 2020 09:24:10 +0200
Subject: [PATCH 3/5] Use library code to handle component creation and string
manipulation
---
.../SubSystems/Conversion/GenericListConverter.cs | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs b/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
index 3dcf42b57a..816ea33a3f 100644
--- a/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
+++ b/src/Castle.Windsor/MicroKernel/SubSystems/Conversion/GenericListConverter.cs
@@ -21,6 +21,8 @@ namespace Castle.MicroKernel.SubSystems.Conversion
using Castle.Core.Configuration;
using Castle.Core.Internal;
+ using Castle.MicroKernel.Context;
+ using Castle.MicroKernel.Util;
[Serializable]
public class GenericListConverter : AbstractTypeConverter
@@ -42,10 +44,16 @@ public override bool CanHandleType(Type type)
public override object PerformConversion(String value, Type targetType)
{
- if (value != null && value.Contains("${"))
+ if (ReferenceExpressionUtil.IsReference(value))
{
- String newValue = value.Replace("${", "").Replace("}", "");
- return Context.Kernel.Resolve(newValue, targetType);
+ string newValue = ReferenceExpressionUtil.ExtractComponentName(value);
+ var handler = Context.Kernel.LoadHandlerByName(newValue, targetType, null);
+ if (handler == null)
+ {
+ throw new ConverterException(string.Format("Component '{0}' was not found in the container.", newValue));
+ }
+
+ return handler.Resolve(Context.CurrentCreationContext ?? CreationContext.CreateEmpty());
}
throw new NotImplementedException();
}
From ecae39bc5e073c36ce62ac95fe3a365a66e7af9e Mon Sep 17 00:00:00 2001
From: ni-mi <51543420+ni-mi@users.noreply.github.com>
Date: Mon, 30 Nov 2020 09:33:29 +0200
Subject: [PATCH 4/5] Add test for referenced property in dictionary
---
.../Config/ConfigurationTestCase.cs | 33 +++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
index 6c84bd9c46..8015cc9808 100644
--- a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
+++ b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
@@ -38,6 +38,39 @@ public class ConfigurationTestCase : AbstractContainerTestCase
+ [Test]
+ [Bug("https://github.com/castleproject/Windsor/issues/574")]
+ public void DictionaryWithReferencedProperty()
+ {
+ var config =
+ @"
+
+
+ Property Value 1
+ Property Value 2
+
+
+
+
+
+
+ #{value1}
+ #{value2}
+
+
+
+
+
+";
+
+ Container.Install(Configuration.FromXml(new StaticContentResource(config)));
+ var stringToStringDictionary = Container.Resolve>("stringToStringDictionary");
+ Assert.NotNull(stringToStringDictionary);
+ Assert.AreEqual(2, stringToStringDictionary.Count);
+ Assert.AreEqual("Property Value 1", stringToStringDictionary["Key 1"]);
+ Assert.AreEqual("Property Value 2", stringToStringDictionary["Key 2"]);
+ }
+
[Test]
[Bug("https://github.com/castleproject/Windsor/issues/574")]
From 5384f68333d87cef9916640c615a546b1ed02df6 Mon Sep 17 00:00:00 2001
From: ni-mi <51543420+ni-mi@users.noreply.github.com>
Date: Fri, 4 Dec 2020 11:07:59 +0200
Subject: [PATCH 5/5] Delete extra whitespaces and modify changelog comment to
reflect the fact that the change is in XML configuration per @jonorossi's
comments
---
CHANGELOG.md | 2 +-
.../Config/ConfigurationTestCase.cs | 10 +---------
2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 55b42ec565..eb6dedba85 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,7 @@ Bugfixes:
- Fix CollectionResolver to allow propagation of inline dependencies (@dvdwouwe, #562)
- Allow DefaultNamingSubSystem derivatives to invalidate the cache which was accidently removed in 5.1.0 (@nativenolde, #569)
- Replace usage of obsolete Castle.Core.Internal.Lock (@generik0, #576)
-- Fix dictionary bug where reference to list components didn't work (@ni-mi, #575)
+- Fix dictionary bug when using XML configuration; A reference to list components inside a dictionary didn't work (@ni-mi, #575)
## 5.1.0 (2020-11-16)
diff --git a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
index 8015cc9808..e8a6858775 100644
--- a/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
+++ b/src/Castle.Windsor.Tests/Config/ConfigurationTestCase.cs
@@ -35,9 +35,6 @@ namespace Castle.MicroKernel.Tests.Configuration
[TestFixture]
public class ConfigurationTestCase : AbstractContainerTestCase
{
-
-
-
[Test]
[Bug("https://github.com/castleproject/Windsor/issues/574")]
public void DictionaryWithReferencedProperty()
@@ -71,7 +68,6 @@ public void DictionaryWithReferencedProperty()
Assert.AreEqual("Property Value 2", stringToStringDictionary["Key 2"]);
}
-
[Test]
[Bug("https://github.com/castleproject/Windsor/issues/574")]
public void DictionaryWithReferencedList()
@@ -123,10 +119,7 @@ public void DictionaryWithReferencedList()
Assert.NotNull(stringToListDictionary);
Assert.AreEqual(2, stringToListDictionary.Count);
}
-
-
-
-
+
[Test]
[Bug("IOC-155")]
public void Type_not_implementing_service_should_throw()
@@ -222,7 +215,6 @@ public void ShouldNotThrowCircularDependencyException()
Assert.NotNull(user.EmptyService);
}
-
[Test]
public void Can_properly_populate_array_dependency_from_xml_config_when_registering_by_convention()
{