Dylan Parry
Dylan Parry

Reputation: 3453

Dependency Injection and ASP.net MVC 5 / Web API 2

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!

Upvotes: 13

Views: 12909

Answers (2)

sunil
sunil

Reputation: 5168

Ninject.MVC3 from Nuget works fine for MVC 4 and MVC 5. I have been using it without any issues.

Upvotes: 2

Wiktor Zychla
Wiktor Zychla

Reputation: 48279

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.

Upvotes: 3

Related Questions