【发布时间】:2015-11-05 20:28:51
【问题描述】:
我们有一个默认的 ASP.NET Web 应用程序,我们希望在其中使用自定义文件提供程序。
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();
});
}
当我们使用 Autofac 之类的自定义 di 容器扩展配置时,不再调用自定义文件提供程序。这曾经在 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>();
}
关于如何使用自定义文件提供程序有什么改变吗?
【问题讨论】:
标签: autofac asp.net-core asp.net-core-mvc