StackOverflowException when using an array of service references

1 view
Skip to first unread message

Reis

unread,
Jul 12, 2010, 9:45:33 PM7/12/10
to Castle Project Users
I'm trying to create an object graph of 3 TestDevice instances, the
first instance owning the second 2.

What I'm finding is that I get a StackOverflowException, because
device2 is being recursively created. That is to say, if I set a
breakpoint on the constructor of TestDevice class, it will get
continually called until the stack overflows.

I'm new to Castle, so I'm guessing there is something simple that I'm
doing wrong.

Any help would be appreciated.


IDevice.cs
++++++++++++++++++++++++++++++++
public interface IDevice
{
string Name { get; }
MessageChannel Channel { get; }
void ProcessMessage(Message message);
void Start();
void Stop();
}

BaseDevice.cs
++++++++++++++++++++++++++++++++
public abstract class BaseDevice : IDevice
{
public BaseDevice(string name)
{
Name = name;
}

public string Name { get; private set;}
public MessageChannel Channel { get; set;}
public virtual void Start() { }
public virtual void Stop() { }
public abstract void ProcessMessage(Message message);
}

TestDevice.cs
++++++++++++++++++++++++++++++++++
public class TestDevice : BaseDevice
{
private readonly List<IDevice> _children;
public TestDevice(string name) : base(name) { ; }

public TestDevice(string name, IDevice[] theChildren) :
this(name)
{
_children = new List<IDevice>(theChildren);
}

public override void ProcessMessage(Message message)
{
foreach(IDevice d in _children)
{
d.ProcessMessage(message);
}
}
}


Channel1.xml
++++++++++++++++++++++++++++++++

<configuration>
<components>
<component id="device2" type="Engine.Test.TestDevice,
Engine.Test">
<parameters>
<name>"device2"</name>
</parameters>
</component>

<component id="device3" type="Engine.Test.TestDevice, Engine.Test"
>
<parameters>
<name>"device3"</name>
</parameters>
</component>


<component id="device1" type="Engine.Test.TestDevice,
Engine.Test">
<parameters>
<name>"device1"</name>
<theChildren>
<array>
<item>${device2}</item>
<item>${device3}</item>
</array>
</theChildren>
</parameters>
</component>
<configuration>


UnitTest.cs
+++++++++++++++++++++++++++++++++++++++++++++++

Unit Test
[Test]
public void BuildSimpleChannel()
{
WindsorContainer container = new WindsorContainer(new
XmlInterpreter(@"..\..\Channel1.xml"));
IDevice device = container.Resolve<IDevice>("device1");
device.Start();
}


Krzysztof Koźmic

unread,
Jul 13, 2010, 2:29:34 AM7/13/10
to castle-pro...@googlegroups.com
I'll look into this.

Krzysztof Koźmic

unread,
Jul 13, 2010, 2:30:55 AM7/13/10
to castle-pro...@googlegroups.com
Can you create a failing test case demonstrating the behavior you'd
expect it to expose?

Krzysztof

On 13/07/2010 11:45 AM, Reis wrote:

Reply all
Reply to author
Forward
0 new messages