Error loading Ninject component ICache

偶尔善良 提交于 2019-12-19 17:37:27

问题


I am using ninject in an asp.net web api project and have started receiving this intermittent ninject error:

"Error loading Ninject component ICache No such component has been registered in the kernel's component container."

I'm using:

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

They are all brought into my project with NuGet I load my Modules in IocConfig.RegisterIoc and have made no other changes or tweaks.

It may be unrelated but the problem started occurring at around the same time as I started injecting IKernel into one of my constructors. I didn't set up a binding for this having read about the "special resolver".

I have read through a number of similar questions on here:

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"

Although in each of these cases the OP has the same error as me the solution is not appropriate - I am not creating child kernels and I'm not using the bugged version of ninject.


回答1:


Found the solution and thought I would share.

The problem was that I was Using Ninject.MVC3 which seems to be wrong package for Web-API.

Instead I need to use Ninject.Web.WebApi-RC package as described by this post:

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

Steps I followed for a fix are

  • Uninstalled Ninject.MVC3 and Ninject.Web.Common
  • delete all of the ninject files from the App_Start folder.
  • install Ninject.Web.Common and Ninject.Web.WebApi-RC from nuget
  • Load my modules in NinjectWebCommon.RegisterServices()


来源:https://stackoverflow.com/questions/14757142/error-loading-ninject-component-icache

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!