Using Unity as Dependency Resolver in ASP.NET MVC 3
January 25, 2011
There have been a lot of improvements and additions to dependency resolving in ASP.NET MVC 3. Even in areas that you first didn’t think about (dependency injection in views) at first.
OK – after my last post, in which I’m using Ninject (with the cool website) I got the questions if it can be done with Unity. Of course it does. This post shows how.
I’m using Ninject because of the super-slick integration with ASP.NET MVC 3 via NuGet. It gives me a “correct” and easy to start with solution. The main part in this found in this App_Start static file, that is run before any other code with the Web Activator mechanism:
And converting that to Unity would be something like this:
Yup – actually...