为什么我无法使用XML autofac配置工作

时间:2016-10-19 17:11:30

标签: xml configuration autofac

我按照这里的例子http://docs.autofac.org/en/latest/configuration/xml.html,用XML代替json,但是无法编译任何东西。我引用了包Microsoft.Framework.ConfigurationModel.Xml(版本1.0.0-beta4),并添加了代码:

// 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()接受一个I​​ConfigurationSourceRoot参数,而ConfigurationBuilder不是这种参数。修补我发现AddXmlFile()方法似乎只是一个配置对象:

var config = new Microsoft.Framework.ConfigurationModel.Configuration();
config.AddXmlFile(filename);

但是Configuration类,成员或扩展上没有Build()方法。我没看到什么?

1 个答案:

答案 0 :(得分:0)

The doc shows Microsoft.Extensions.Configuration not Microsoft.Framework.Configuration. Microsoft renamed a lot of stuff before releasing .NET Core so it appears you're referencing the wrong thing. Try using the full release versions of everything and see if you have better luck.