2010-04-07 36 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