MVC5 Autofac:找不到的视图

我创建了非常简单的MVC 5.0应用程序,我推送到GitHub存储库: https : //github.com/marxin/mvc-sample 。 我的动机是使用mono 3.2.3在Linux上执行app。

我想添加Autofac NuGet包(更确切地说是3.3.0),这对我来说很好。 问题是,如果我添加Autofac.Mvc5集成包,Razor将停止处理以下错误:

System.InvalidOperationException The view found at '~/Views/Home/Index.cshtml' was not created. Description: HTTP 500.Error processing request. Details: Non-web exception. Exception origin (name of application or object): System.Web.Mvc. Exception stack trace: at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x00000] in :0 at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00000] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in :0 at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in :0 

差异: https : //github.com/marxin/mvc-sample/commit/ca980adcf1d67e2e74729b27b11c26065dd2567e

能否帮助我帮助我注册Autofac以启用Razor视图页面必须达到的最低要求?

如果我尝试aspx模板,一切正常。

谢谢你,马丁

好的,问题出在web.config参考定义中,请参阅以下差异: https : //github.com/marxin/mvc-sample/commit/3d5d7fef6f0284a96518852e0d892ca6205f5679

顺便说一句。 MVC5实际上与单声道不兼容,但有拉动请求可以修复缺失的function。

谢谢

您需要注册您的IoC容器以进行autofac。 在你的global.asax中

 protected void Application_Start() { var builder = new ContainerBuilder(); builder.RegisterControllers(typeof(MvcApplication).Assembly); var container = builder.Build(); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // Other MVC setup... }