8
votes

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.

1

1 Answers

9
votes

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.