【问题标题】:Does autofac supports the new Web Api 2autofac 是否支持新的 Web Api 2
【发布时间】:2014-01-14 11:26:49
【问题描述】:

我正在开发一个 web api,作为 VS 2013、MVC 5、API 2 上的 MVC/API ASP.NET 的一部分,但我的 AutofacWebApiDependencyResolver 每次尝试注册时都会引发异常:

附加信息:覆盖成员时违反了继承安全规则:“Autofac.Integration.WebApi.AutofacWebApiDependencyResolver.BeginScope()”。重写方法的安全可访问性必须与被重写方法的安全可访问性相匹配。

我尝试了很多事情都没有成功。请记住,我有最新的 autofac.webapi.nupkg,但它仍然无法正常工作。

【问题讨论】:

    标签: c# asp.net-mvc asp.net-web-api autofac asp.net-mvc-5


    【解决方案1】:

    您需要安装一个名为 Autofac ASP.NET MVC5 IntegrationAutofac ASP.NET Web API 2 Integration 的 NuGet 包,当然还有最新版本的 Autofac,目前是 3.2.0。

    由于某种原因,这些包不是在结果中排​​在第一位,而是排在第 2 页,这有点令人失望。

    【讨论】:

      【解决方案2】:

      当您查找 nuget 包时,请搜索“autofac webapi 2”。不要使用包“Autofac.Webapi”,使用“Autofac.WebApi2”。这为我解决了这个问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-01
        相关资源
        最近更新 更多