asp.net-web-api – 在WebApi2项目中使用CacheOutput属性时,依赖
发布时间:2020-12-16 03:29:28 所属栏目:asp.Net 来源:网络整理
导读:在我的ASP.NET WebApi2项目中,我决定使用 Strathweb.CacheOutput.WebApi2 package来提供缓存和电子标签功能.但是,在放入CacheOutput属性后,我开始收到错误: Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed,typ
在我的ASP.NET WebApi2项目中,我决定使用
Strathweb.CacheOutput.WebApi2 package来提供缓存和电子标签功能.但是,在放入CacheOutput属性后,我开始收到错误:
Microsoft.Practices.Unity.ResolutionFailedException: Resolution of the dependency failed,type = "WebApi.OutputCache.Core.Cache.IApiOutputCache",name = "(none)". Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type,WebApi.OutputCache.Core.Cache.IApiOutputCache,is an interface and cannot be constructed. Are you missing a type mapping? 显然,包的内部DI容器无法解析缓存提供程序. 我使用属性的方式: [HttpGet,Route("")] [CacheOutput(ClientTimeSpan = 60 * 60 * 4,ServerTimeSpan = 60 * 60 * 4)] public HttpResponseMessage Get( string products,int? startYear = null,int? endYear = null,int? drillDownYear = null,int? drilldownMonth = null,string callback = "") { ... } 请注意,我也在我的应用程序中使用Unity作为DI容器. 解决方法
lib使用以下逻辑来查找缓存提供程序(使用第一个匹配项):
>检查Func< IApiOutputCache>在您的HttpConfiguration的属性中 通常,IDependencyResolver在找不到注册时将返回null – 在这种情况下,您的Unity实现似乎正在抛出Ex. 您可以通过切换到更好的DI :)来缓解这种情况,或者只是在Unity容器中将新的MemoryCacheDefault()单例注册为IApiOutputCache. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – 概念类型中的成员数量不匹配 – 但确实如此
- asp.net – 以编程方式在ASPX页面中设置’visible’属性的值
- asp.net-core-mvc – 如何在Asp.Net Core中自定义Developer
- 如何使用ASP.NET&C#从服务器端确定浏览器类型?
- asp.net-mvc – MvcSiteMapProvider安装错误
- asp.net-mvc – asp.net mvc url action忽略旧参数值
- [你必须知道的.NET] 第一回:恩怨情仇:is和as
- ASP.NET Core文件上传与下载实例(多种上传方式)
- asp.net-mvc – 使用MVC的AuthorizeAttribute和多组角色?
- asp.net – RegularExpressionValidator VS Ajax 1.0.20229
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC日历
- asp.net – 如何在EnableSessionState =“False”
- asp.net-mvc – 我什么时候应该在asp.net mvc应用
- asp.net – 使用System.Web.Providers的Optimist
- asp.net-mvc – ASP.NET MVC ActionFilter参数绑
- Godaddy ASP.NET会员数据库困境
- asp.net-mvc – 如何根据MVC中的其他参数值在运行
- 在asp.net中是否有等效的回声c#
- 将ASP.NET添加到ASP.NET文本框控件的OnBlur属性
- asp.net-web-api – 将域对象元数据暴露给breeze
热点阅读