I've created a default MVC5 web application in Visual Studio 2013, and added in the StructureMap.MVC5 package from NuGet.
I've created an interface ITester
and an implementation Tester
, and my controller action takes an ITester
as a parameter.
But when I run the project I get the error Cannot create an instance of an interface
.
According to this is should just work. I also get the same result if I explicitly tell structuremap to use Tester
for ITester
(rather than relying on the default conventions).
I've used StructureMap.MVC4 with MVC4 web applications before with no problems.
Out of the box it's going to do constructor injection only.
This will work
public HomeController(ITester tester)
{
_tester = tester;
}
This will cause the error you are seeing
public ActionResult Index(ITester tester)
{
return View();
}