我想为每个 XML 配置一个具有属性的模块,其中包含 MyObject 类的列表。我的 Module 和 MyObject 类看起来像:
public class MyModule : Module
{
public IList<MyObject> MyObjects { get; set; }
protected override void Load(ContainerBuilder builder)
{
base.Load(builder);
// Do something with MyObjects.
}
}
public class MyObject
{
public string Id { get; set; }
public bool IsVisable { get; set; }
}
我的假设是在 XML 中像这样配置它:
<modules name="MyModule">
<type>...</type>
<properties>
<MyObjects>
<MyObject>
<Id>1234</Id>
<IsVisilble>false</IsVisilble>
</MyObject>
</MyObjects>
</properties>
但是如果我运行它,我会得到以下异常:
Unable to convert object of type 'Autofac.Configuration.Util.ConfiguredDictionaryParameter' to type 'System.Collections.Generic.IList`1[MyObject]'
我正在使用 Autofac 4.5.0 和 Autofac.Configuration 4.0.1。
我究竟做错了什么?有没有办法让它工作?