autofac是否支持新的Web Api 2

时间:2022-05-11 15:26:50

I'm developing a web api as part of a MVC/API ASP.NET on VS 2013, MVC 5, API 2, but my AutofacWebApiDependencyResolver throws an exception every time I try to register it:

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

Additional information: Inheritance security rules violated while overriding member: 'Autofac.Integration.WebApi.AutofacWebApiDependencyResolver.BeginScope()'. Security accessibility of the overriding method must match the security accessibility of the method being overriden.

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

I've tried a lot of things unsuccessfully. Keep in mind I have the latest autofac.webapi.nupkg but it still not working.

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

2 个解决方案

#1


18  

You need to install a NuGet package called Autofac ASP.NET MVC5 Integration as well as Autofac ASP.NET Web API 2 Integration and of course the latest version of Autofac which currently is 3.2.0.

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

For some reason these packages are not first in the results but rather page 2, which is kind of a bummer.

出于某种原因,这些包不是结果中的第一个,而是第2页,这是一种无赖。

#2


8  

When you look for the nuget package, search for "autofac webapi 2". Do not use the package "Autofac.Webapi", use "Autofac.WebApi2". This fixed the problem for me.

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

#1


18  

You need to install a NuGet package called Autofac ASP.NET MVC5 Integration as well as Autofac ASP.NET Web API 2 Integration and of course the latest version of Autofac which currently is 3.2.0.

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

For some reason these packages are not first in the results but rather page 2, which is kind of a bummer.

出于某种原因,这些包不是结果中的第一个,而是第2页,这是一种无赖。

#2


8  

When you look for the nuget package, search for "autofac webapi 2". Do not use the package "Autofac.Webapi", use "Autofac.WebApi2". This fixed the problem for me.

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