views:

19

answers:

1

I am trying to figure out how to setup StructureMap (using an XML Configuration file). One class has a constructor with a list containing instances of a 2nd class:

public interface ITestDocType { }

class TestDocType : ITestDocType
{
    public List<AttributeRef> AttrRefs { get; set; }

    public TestDocType(List<AttributeRef> attrRefs)
    {
        AttrRefs = attrRefs;
    }
}

public class AttributeRef
{
    public AttributeRef(string name, string xpath, string value)
    {
        Name = name;
        Xpath = xpath;
        Value = value;
    }

    public string Name { get; set; }
    public string Xpath { get; set; }
    public string Value { get; set; }
}

I was hoping to be able to inline the instances of AttributeRef in my configuration file, but not entirely sure how its done (or if its possible).

<DefaultInstance PluginType="ITestDocType" PluggedType="TestDocType">
    <attrRefs>
       // Would like to specify one to many AttributeRef instances inline here
    </attrRefs>
</DefaultInstance>
A: 

Ok.. I figured it out, and it was described pretty nicely in the documentation.. I just needed to read it a few times over to fully understand.

  <DefaultInstance PluginType="yyy" 
               PluggedType="yyy">
      <attrRefs>
          <Child>
              <DefaultInstance PluginType="xxx"
                               PluggedType="xxx"
                               name="id" x
                               path="/item/@idd" 
                               attrValue="none">
              </DefaultInstance>
          </Child>
      </attrRefs>
  </DefaultInstance>

As you can see, "attrRefs" is the name of the parameter in the constructor that takes List, and for each element you want to add to that list, wrap the DefaultInstance element inside a "Child" element.

Bryce Fischer
ok, so this doesn't work out the way its supposed to... When the parent instance is retrieved, the "attrRefs" parameter contains an empty list... Back to the drawing board.
Bryce Fischer