0
我們有一個默認的ASP.NET Web應用程序,我們在其中使用自定義文件提供程序。ASP.NET 5 beta8 Autofac自定義文件提供程序
public class CustomFileProvider : IFileProvider
{
public IDirectoryContents GetDirectoryContents(string subpath)
{
...
}
public IFileInfo GetFileInfo(string subpath)
{
...
}
public IChangeToken Watch(string filter)
{
...
}
}
當我們使用下面的代碼配置提供程序時,它工作正常,自定義文件提供程序被框架調用。
public void ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
services.Configure<RazorViewEngineOptions>(options =>
{
// replace the fileprovider with the custom file provider
options.FileProvider = new CustomFileProvider();
});
}
當我們使用自定義di容器如Autofac擴展配置時,不再調用自定義文件提供程序。這用於在beta5中正常工作。
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// Add MVC services to the services container.
services.AddMvc();
services.Configure<RazorViewEngineOptions>(options =>
{
// replace the fileprovider with the custom file provider
options.FileProvider = new CustomFileProvider();
});
// Create the Autofac container builder.
var builder = new ContainerBuilder();
// Populate the services.
builder.Populate(services);
// Build the container.
var container = builder.Build();
// Resolve and return the service provider.
return container.Resolve<IServiceProvider>();
}
在如何使用自定義文件提供程序方面做了些改變嗎?