Social

Husband, Father, Software Developer in .NET

Using Simple Injector with ASP.NET MVC 5

While ASP.NET Core has built-in capabilities for dependency injection, when attempting to accomplish this in MVC 5 one may come across a strange error:

No parameterless constructor defined for this object.

At a glance this is not entirely helpful. Adding a parameterless constructor is not a viable solution when you need to inject an interface. A third party library is still the best option for accomplishing this in MVC 5. This is a matter of preference, but for my needs Simple Injector continually stands out as one of the fastest options. It’s also lightweight and easy to install. Here is an example service for the HomeController: