Constructor Dependency Injection in a ASP.NET MVC Controller

asp.net-mvc, dependency-injection

Solution

If you want to have parameterless constructors you have to define a custom controller factory. Phil Haack has a great blog post about the subject.

If you don't want to roll your own controller factory you can get them pre-made in the ASP.NET MVC Contrib project at codeplex/github.

Problem

Consider: ``` public class HomeController : Controller { private IDependency dependency; public HomeController(IDependency dependency) { this.dependency = dependency; } } ``` And the fact that Controllers in ASP.NET MVC must have one empty default constructor is there any way other than defining an empty (and useless in my opinion) constructor for DI?

Original source