I have a simple MVC3 Web application. I use structureMap as a dependency Injection.
It works fine with my HomeController, but when I go to a second Controller I have thi error:
MissingMethodException : No zero parameters constructor.
I followed every step I found in tutorials…
Thx.
Here’s the code :
public class HomeController : AuthorizedController
{
IRepository<User> _repository;
public HomeController(IRepository<User> repository)
{
_repository = repository;
}
}
public class AccountController : AuthorizedController
{
private readonly IRepository<User> _repository;
public AccountController(IRepository<User> repository)
{
_repository = repository;
}
}
And I use this simple injection:
For<IRepository<User>>().Use<UserRepository>();
Are u sure it is working with HomeController? if you have error for second controllor then error should be present for HomeController?
Make sure that your base controller AuthorizedController has a parameterless public constructor
If you do not define a constructor for a class, a parameterless constructor will be created. However, if you define a constructor with parameters, no parameterless constructor will be created.