在我的MVC网络应用程序中,我收到以下错误:
由于HttpContext,无法创建请求生存期范围 不可用
当我谷歌时,我发现解决方案是升级我的autofac.Mvc dll
,但我只使用autofac dll
,Autofac.Integration.Mvc dll
等,我无法找到autofac.MVC
的任何dll 1}}
我错过了任何dll吗?
Autofac
,Autofac.MVC
,Autofac.Integration.Mvc
dll有什么区别?
答案 0 :(得分:1)
The documentation on MVC integration may be of help to you继续,但我也要回答你的问题。
首先,了解 NuGet包和 DLL (也称为程序集)之间存在差异,这很有用。 很多时候 NuGet包中的程序集的名称与包相同,但有时内部的程序集具有不同的名称。 (有时NuGet包有多个程序集。)
所以,回答你的问题:
NuGet Package Assembly Inside Purpose ------------- --------------------------- ------------------------- Autofac Autofac.dll Core Autofac Autofac.Mvc5 Autofac.Integration.Mvc.dll ASP.NET MVC 5 integration
因此,当您看到需要更新MVC集成时,它所转换的是您需要最新版本的Autofac.Mvc5 NuGet包。
答案 1 :(得分:0)
当您将autofac集成到与autofac相同的mvc应用程序时,将使用Autofac.mvc。 WebAPI,当您为WebAPI的应用程序集成autofac时使用。 MVC集成为控制器,模型绑定器,操作过滤器和视图提供依赖注入集成。它还增加了每个请求的终身支持。
因为RegisterModelBinders()扩展方法使用程序集扫描来添加模型绑定程序,所以需要指定要为其注册模型绑定程序(IModelBinder实现)的类型。 这是通过使用Autofac.Integration.Mvc.ModelBinderTypeAttribute完成的 同样,此dll支持许多其他mvc集成,这些集成在此链接中列出 https://autofac.org/apidoc/html/F26C16A.htm
Autofac允许您注入构造函数参数以及属性和方法注入
因此,我们需要所有三个dll在mvc应用程序中进行autofac up和functional。
如果您需要进一步澄清,请与我们联系。
谢谢!