MVC 3, MVC4, Technical

Dependency Injection with ninject.mvc3 nuget

Quick post, just because this is mega easy.

Traditionally, adding dependency injection with any standard injection package to an MVC solution would normally mean that you would have to write a Controller Factory and wire it up in your Application_Start() method.

If you want to add dependency injection into an MVC solution, just add one of the pre-baked nuget packages that does the MVC wire up for you:

It’s just much easier – these packages contain code that has done the legwork of wiring up a custom controller factory for you.

Looking specifically at the Ninject.MVC3 package, simply add the NuGet reference. This will add a “NinjectWebCommon.cs” file into your “App_Start” folder:

You can then edit the RegisterServices(IKernel kernel) method to configure your bindings:

        private static void RegisterServices(IKernel kernel)

One thought on “Dependency Injection with ninject.mvc3 nuget

  1. I was with them back in 2007 – left after their service was down most of the month. Support staff were very unhelpful / basically didn’t know what was going on.

    Glad I left when I did

Leave a Reply to Alex Cancel reply

Your email address will not be published. Required fields are marked *