【问题标题】:ASP.NET 5 beta8 Custom File Provider with Autofac带有 Autofac 的 ASP.NET 5 beta8 自定义文件提供程序
【发布时间】: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


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2011-08-18
    • 1970-01-01
    • 2015-03-24
    • 1970-01-01
    • 1970-01-01
    • 2011-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多