Reis
unread,Jul 12, 2010, 9:45:33 PM7/12/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
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();
}