What are all this Ninject packages in nuget for integrating with WEB API?
Asked Answered
M

1

8

I am building an application using Ninject (MVC5 + WEBAPI). And having some issues figuring out which ones of the many answers explain the most up to date solution to integrate Ninject and WebApi. So I have the following packages installed:

  • Ninject
  • Ninject Integration for WebApi2
  • Ninject.MVC5
  • Ninject.Web.Common
  • Ninject.Web.Common.WebHost

Some people suggest that my initial problem (Ninject is not resolving the API controllers instantiation) should be resolved by either:

  • Installing another package (Ninject.Web.WebApi-RC, Ninject.WebAPI, etc.)
  • Creating my own dependency resolver
  • Installing Ninject Owin host
  • Mix any of the above and hope it finally works.

So it comes down to, what are all this packages? Also, do I need to use Owin hosting? I got an 'Unable to find package Ninject.Web.WebApi' message from nuget console so I assume this one doesn't exist anymore?.

Thanks.

Monologue answered 30/6, 2014 at 14:53 Comment(0)
H
9

There are several packages you need to get Ninject working with Web API 2:

  • Ninject (base library)
  • Ninject.Web.Common
  • Ninject.Web.Common.WebHost
  • Ninject.Web.WebApi.WebHost ("Ninject Web Host for WebApi 2")
  • Ninject.Web.WebApi ("Ninject Integration for WebApi 2")

After you install all of those, you'll find a pre-built NinjectWebCommon class in your App_Start folder. Just add you bindings to the RegisterServices() method.

Helmuth answered 1/7, 2014 at 13:9 Comment(4)
Thanks Pharylon, so, it seems this answer https://mcmap.net/q/276789/-how-to-use-ninject-with-asp-net-web-api is now outdated? We don't need to implement the custom dependency resolver anymore. What's the difference between the two web host packages?Monologue
One is simply the base Webhost package, and the other adds the WebApi 2 functionality. But, yes, that link is outdated now. I think Web Api 2 changed some core DI stuff, so there are new Ninject packages.Helmuth
Yes, but I am more interested in knowing what they do, hosting for what? Do I need the common.webhost if I have the webapi.webhost? What if I use owin webhost? Do I still need the others?Monologue
After long time and installing it all and making it work (not knowing exactly what this packages do) I think it is fare to say this is the closest answer I will get. See also groups.google.com/forum/#!topic/ninject/HNhi7nv28-M The same question about the two webhosts.Monologue

© 2022 - 2024 — McMap. All rights reserved.