asp.net-web-api - 加载 Ninject 组件 ICache 时出错

标签 asp.net-web-api ninject

我在 asp.net web api 项目中使用 ninject 并开始收到此间歇性 ninject 错误:

" 加载 Ninject 组件 ICache 时出错
没有在内核的组件容器中注册此类组件。
"

我正在使用:

  • 忍者 3.0.1.10
  • Ninject.MVC3 3.0.0.6
  • Ninject.Web.Common 3.0.0.7

  • 它们都通过 NuGet 带入我的项目中,我在 IocConfig.RegisterIoc 中加载了我的模块,并且没有进行其他更改或调整。

    这可能是无关的,但问题开始发生在我开始将 IKernel 注入(inject)我的一个构造函数的大约同一时间。在阅读了有关“特殊解析器”的信息后,我没有为此设置绑定(bind)。

    我在这里阅读了许多类似的问题:

    Ninject + "Error loading Ninject component ICache"

    Ninject and ChildKernel in MVC3 project: "Error loading Ninject component ICache"

    Randomly-Occurring Ninject Exception: "Error loading Ninject component ICache"

    尽管在每种情况下,OP 都与我有相同的错误,但解决方案并不合适——我没有创建子内核,也没有使用错误版本的 ninject。

    最佳答案

    找到了解决方案,并认为我会分享。

    问题是我正在使用 Ninject.MVC3,这似乎是 Web-API 的错误包。

    相反,我需要使用本文所述的 Ninject.Web.WebApi-RC 包:

    http://www.eyecatch.no/blog/2012/06/using-ninject-with-webapi-rc/

    我遵循的修复步骤是

  • 已卸载 Ninject.MVC3 和 Ninject.Web.Common
  • 从 App_Start 文件夹中删除所有 ninject 文件。
  • 从 nuget
  • 安装 Ninject.Web.Common 和 Ninject.Web.WebApi-RC
  • 在 NinjectWebCommon.RegisterServices()
  • 中加载我的模块

    关于asp.net-web-api - 加载 Ninject 组件 ICache 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14757142/

    相关文章:

    rest - 如何通过http客户端强制调用restful服务?

    asp.net-mvc - 洋葱架构 : Business Services Interfaces and Implementation

    javascript - 如何使用 Angular 和 webapi 或 mvc 处理测验应用程序中的安全性?

    c# - 将主体/用户上下文设置为用户对象

    asp.net-mvc-3 - 在 MVC3 应用程序中将 Ninject 与自定义角色提供程序结合使用

    c# - Ninject 绑定(bind),接口(interface)到接口(interface)

    asp.net-mvc - Ninject.Extensions.Logging.nlog2 - 如何?

    asp.net-mvc - 模型的依赖注入(inject)

    c# - 无法在 IIS 上托管 asp .net web api

    c# - Web Api 路由处理程序更改路由数据