2010-04-07 189 views
0

我想弄清楚如何设置StructureMap(使用XML配置文件)。一类具有包含第二类的实例列表的构造函数:StructureMap非原始类型列表

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

我希望能够内嵌AttributeRef的情况下,在我的配置文件,但不完全确定如何做(或者其可能)。

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

回答

0

好吧..我想它了,它被described pretty nicely in the documentation ..我只需要读它几次在充分了解。

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

正如你所看到的,“attrRefs”是在采用列表构造函数的参数的名称,以及要添加到列表中的每个元素,包装一个“孩子”元素中的DefaultInstance元素。

+0

好吧,所以这不会按照它应该的方式工作......当父实例被检索到时,“attrRefs”参数包含一个空列表......回到绘图板。 – 2010-04-09 13:29:27