I’m in the process of creating a new web site using ASP.net MVC 5, and it’s also going to have an API using Web API 2. In the past I’ve used Ninject for handling Dependency Injection, but it always seemed a bit flaky with Web API.
I’ve had a look at the Ninject web site, and it doesn’t look like there’s a plugin for MVC 5 (unless the MVC 3 one still works?) and there’s not much out there about using it with MVC 5 (not that I can find anyway).
So I was wondering what the recommended method is for Dependency Injection with MVC 5 and Web API is? Is there anything built in now, or do I still need to use a third party solution? Are there any tutorials out there?
Thanks!
Take a look at this tutorial, it involves a custom DependencyResolver
.
http://www.asp.net/web-api/overview/extensibility/using-the-web-api-dependency-resolver
Seems like there is a nuget package
https://www.nuget.org/packages/Ninject.WebApi.DependencyResolver/
but I haven't used it and cannot recommend it.
Ninject.MVC3 from Nuget works fine for MVC 4 and MVC 5. I have been using it without any issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With