NinjectHttpApplication doesn't work after porting to web api 2
Asked Answered
A

2

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.
Ashantiashbaugh answered 6/5, 2014 at 20:58 Comment(1)
Do you have Ninject.Web.WebApi 3.2.0.0 from Nuget?Watcher
B
19

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.

Brioche answered 18/6, 2014 at 16:25 Comment(2)
Thank you. Seems that workaround was common place :)Poem
This worked for me too. I myself applied the workaround followinig this article link, before installing the nuget package Ninject.Web.WebApiMaricela
A
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.

Ashantiashbaugh answered 7/5, 2014 at 23:19 Comment(4)
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?Transilluminate
I realise that it's probably too late already, but here it is: gist.github.com/Deadarius/…Ashantiashbaugh
This gist won't provide all infrastructure to enable web api 2 injection.Angelynanger
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: // #16383482Gurney

© 2022 - 2024 — McMap. All rights reserved.