C# 非基本类型的StructureMap列表
我试图弄清楚如何使用XML配置文件设置StructureMap。一个类有一个构造函数,其列表包含第二个类的实例:C# 非基本类型的StructureMap列表,c#,structuremap,C#,Structuremap,我试图弄清楚如何使用XML配置文件设置StructureMap。一个类有一个构造函数,其列表包含第二个类的实例: public interface ITestDocType { } class TestDocType : ITestDocType { public List<AttributeRef> AttrRefs { get; set; } public TestDocType(List<AttributeRef> attrRefs) {
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>
好的。。我想出来了,结果。。我只需要读几遍就可以完全理解了
<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元素包装到子元素中。ok,因此这不是它应该的方式。。。检索父实例时,attrRefs参数包含一个空列表。。。回到绘图板上。