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();
    }


-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" 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-users?hl=en.

Reply via email to