0
我跟着http://docs.autofac.org/en/latest/configuration/xml.html这个例子,用XML代替了json,但无法获得任何东西来编译。我所引用的包Microsoft.Framework.ConfigurationModel.Xml(版本1.0.0-BETA4),和添加的代码:为什么我不能使用XML autofac配置来工作
// Add the configuration to the ConfigurationBuilder.
var config = new ConfigurationBuilder();
config.AddXmlFile("something.xml");
// Register the ConfigurationModule with Autofac.
var module = new ConfigurationModule(config.Build());
var builder = new ContainerBuilder();
builder.RegisterModule(module);
麻烦的是,延伸方法AddXmlFile()需要一个IConfigurationSourceRoot参数,其ConfigurationBuilder不是一种类型。修修补补左右我发现AddXmlFile()方法似乎只喜欢一个配置对象:
var config = new Microsoft.Framework.ConfigurationModel.Configuration();
config.AddXmlFile(filename);
但有一个配置类,成员或分机号码生成()方法。我没有看到什么?
好的。不久之前,您所需要的只是Autofac.Configuration。现在你需要加上其他8个软件包。另外,json配置工作,但不是xml的。这将产生一个重复键错误: <模块类型= “SomeModule”/> <模块类型= “AnotherModule”/> –
Dan
阅读文档。您错过了XML项目的序号命名。 http://autofac.readthedocs.io/en/latest/configuration/xml.html –
实际上,文档只讨论使用序号而不是。从他们的文档: 在任何情况下,我尝试添加“名称”属性以前,它仍然无法正常工作。它让我通过重复键错误进入ArgumentNullException。完全相同的配置在json中起作用。你看到的全是我所做的 - 包括两个模块。 Json是。谢谢你的帮助。 –
Dan