首页 asp.Net Autofac和ASP.NET Web API ApiController

Autofac和ASP.NET Web API ApiController

我一直在使用autofac与MVC 3一段时间,并喜欢它.我最近将一个项目升级到MVC 4,除了Web Api ApiController之外,所有内容似乎都很有效.我得到以下例外. An error occurred when trying to create a controller of type MyNamespace.Foo.CustomApiController. Mak

我一直在使用autofac与MVC 3一段时间,并喜欢它.我最近将一个项目升级到MVC 4,除了Web Api ApiController之外,所有内容似乎都很有效.我得到以下例外.

An error occurred when trying to create a controller of type 'MyNamespace.Foo.CustomApiController'. Make sure that the controller has a parameterless public constructor.

这似乎是DI通过autofac的问题.我错过了一些东西,还是在作品中有东西.我知道,MVC4刚刚出来,是一个beta,所以我不期望很多,但想到我可能会缺少一些东西.

解决方法

我已经在NuGet上发布了用于测试版MVC 4和Web API的Autofac集成包.集成将根据控制器请求(MVC控制器或API控制器,取决于集成)创建一个Autofac使用寿命范围.这意味着控制器及其依赖将在每次调用结束时自动处理.这两个软件包可以并排安装在同一个项目中.

MVC 4

https://nuget.org/packages/Autofac.Mvc4

http://alexmg.com/post/2012/03/09/Autofac-ASPNET-MVC-4-(Beta)-Integration.aspx

Web API

https://nuget.org/packages/Autofac.WebApi/

http://alexmg.com/post/2012/03/09/Autofac-ASPNET-Web-API-(Beta)-Integration.aspx

链接现在已修复.

本文来自网络,不代表青岛站长网立场。转载请注明出处: https://www.0532zz.com/html/kaifa/asp-net/20200925/10657.html
上一篇
下一篇

作者: dawei

【声明】:青岛站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

为您推荐

返回顶部