Autofac - 使用对象配置模块列表属性

时间:2017-11-07 08:09:20

标签: autofac autofac-module autofac-configuration

我想为每个XML配置一个带有属性的模块,该属性包含MyObject类的列表。 我的模块和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.Configuration 4.0.1中使用Autofac 4.5.0。

我做错了什么?有没有办法让它发挥作用?

0 个答案:

没有答案
相关问题