10

I have ported my Web Api application to Web Api 2 and installed ninject web api pacckage. But now I am getting an error:

Error activating ModelValidatorProvider using binding from ModelValidatorProvider to NinjectDefaultModelValidatorProvider

A cyclical dependency was detected between the constructors of two services.
Alex Lapa
  • 1,149
  • 11
  • 21

2 Answers2

18

I had this same issue. I got it when I added Ninject.Web.WebApi as a Nuget package.

To resolve the issue, I had to remove a workaround that I had previously implemented.

In the previous workaround, I had set the dependency resolver in NinjectWebCommon to a custom class that implemented IDependencyResolver.

In short, if you have a line similar to GlobalConfiguration.Configuration.DependencyResolver = new NinjectDependencyResolver(kernel); in NinjectWebCommon's CreateKernel(), remove it.

  • Thank you. Seems that workaround was common place :) – Mark OB Aug 27 '14 at 09:08
  • This worked for me too. I myself applied the workaround followinig this article [link](http://www.peterprovost.org/blog/2012/06/19/adding-ninject-to-web-api/), before installing the nuget package Ninject.Web.WebApi – Daniele Feb 12 '15 at 16:46
2

Didn't manage to make it working. As a workaround just removed Ninject.Web.WebApi package completely and now using hand-rolled web api dependency resolver for ninject. To be honest, it's so simple that I don't really see a reason to use this nuget package for integration with ninject.

Alex Lapa
  • 1,149
  • 11
  • 21
  • 1
    Hi, I'm running into the same problem however I am not referencing the Ninject.Web.WebApi package. The only 2 I am referencing are Ninject and Ninject.Web.Common. What was your solution to this? Can you provide the hand-rolled web api dependency resolver you are using? – MikeAtCodeSmart May 13 '14 at 17:06
  • 1
    I realise that it's probably too late already, but here it is: https://gist.github.com/Deadarius/7d68b5d82a8a9ddad59e#file-ninjectdependencyresolver-cs – Alex Lapa Jun 24 '14 at 22:52
  • This gist won't provide all infrastructure to enable web api 2 injection. – Rafael Diego Nicoletti Oct 15 '14 at 01:10
  • Me, too. Removed the NuGet package (I couldn't figure out how it was supposed to work, esp since it doesn't implement IDependencyResolver) and used the GitHub gyst code in this SO question: // http://stackoverflow.com/questions/16382982/configuring-ninject-with-asp-net-mvc-web-api – Luke Puplett Jan 09 '15 at 14:07