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

2

13

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!

Thier answered 20/11, 2013 at 11:27 Comment(0)
B
2

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

Broadax answered 4/12, 2013 at 23:18 Comment(0)
E
3

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.

Ending answered 20/11, 2013 at 12:5 Comment(0)
B
2

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

Broadax answered 4/12, 2013 at 23:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.