Possible bug in WindsorContainer

1 view
Skip to first unread message

Gian Marco

unread,
Oct 9, 2009, 9:40:14 AM10/9/09
to Castle Project Development List
Hi,
i have problems specifying string parameters with xml configuration,
following is a test that shows 2 different behaviours: one with the
problem and one without.

----- START GenericBugTest.cs
----------------------------------------------------------------------------------------------------

namespace SpikeWindsor
{
[TestFixture]
public class GenericBugTest
{
[Test]
public void Bug()
{
var exception = Assert.Throws<DependencyResolverException>(() =>
new WindsorContainer(new XmlInterpreter("GenericsWithStrings.xml")));
Assert.That(exception.Message, Is.EqualTo("Key invalid for
parameter key. Thus the kernel was unable to override the service
dependency"));
}

[Test]
public void Correct()
{
var container = new WindsorContainer(new XmlInterpreter
("GenericsWithComponents.xml"));
Assert.That(container.Resolve<TypeWith2Generics<string, string>>
("typewith2generics"), Is.Not.Null);
}
}

public class TypeWith2Generics<TKey, TValue>
{
private readonly TKey _key;
private readonly TValue _value;

public TypeWith2Generics(TKey key, TValue value)
{
_key = key;
_value = value;
}
}

public class Component {}
}

----- END GenericBugTest.cs
----------------------------------------------------------------------------------------------------

----- START GenericsWithComponents.xml
----------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<components>
<component id="typewith2generics"
type="SpikeWindsor.TypeWith2Generics`2, SpikeWindsor">
<parameters>
<key>${component}</key>
<value>${component}</value>
</parameters>
</component>
<component id="component" type="SpikeWindsor.Component,
SpikeWindsor" />
</components>
</configuration>
----- END GenericsWithComponents.xml
----------------------------------------------------------------------------------------------------

----- START GenericsWithStrings.xml
----------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<components>
<component id="typewith2generics"
type="SpikeWindsor.TypeWith2Generics`2, SpikeWindsor">
<parameters>
<key>string value</key>
<value>string value 2</value>
</parameters>
</component>
</components>
</configuration>
----- END GenericsWithStrings.xml
----------------------------------------------------------------------------------------------------


Is this behaviour correct or it's a bug?

Thanks!

PS: this test project is available at

https://randomhacking.googlecode.com/svn/trunk/dotnet/SpikeWindsor

for the references checkout from

https://randomhacking.googlecode.com/svn/trunk/dotnet/


Mauricio Scheffer

unread,
Oct 9, 2009, 11:31:03 AM10/9/09
to Castle Project Development List
In GenericsWithStrings.xml, the type parameters should be specified
for TypeWith2Generics, since you already know that they are strings,
i.e.:

type="SpikeWindsor.TypeWith2Generics`2[[System.String,
System.String]], SpikeWindsor"

(I always forget if it's one or two brackets)
Reply all
Reply to author
Forward
0 new messages