开发者

Using ELMAH with Areas in MVC 2

开发者 https://www.devze.com 2023-02-06 03:16 出处:网络
I\'m following this blog post about setting up ELMAH with MVC: http://dotnetdarren.wordpress.com/2010/07/27/logging-on-mvc-part-1/

I'm following this blog post about setting up ELMAH with MVC:

http://dotnetdarren.wordpress.com/2010/07/27/logging-on-mvc-part-1/

I've only done part 1. Everything works correctly if I simply go to the Home controller, and then cause an error. I can view /elmah.axd as well, and my errors are logging in the database correctly.

However, I've added an area to my application named Admin. If I navigate to /Admin, I receive the following error:

System.MissingMethodException: No parameterless constructor defined for this object.

public override IController CreateController(RequestContext requestContext, string controllerName)
{
    var controller = base.CreateController(requestContext, controllerName); //Error here

    var c = controller as Controller;

I'm assuming this has something to do with my Area.

Does anyone know how to fix this?

EDIT for jfar:

For instance, I have an Employees controller in my Admin area:

public class EmployeesController : Controller
{
    private IEmployeesRepository employeesRepository;

    public EmployeesController(IEmployeesRepository employeesRepository)
    {
        this.employeesRepository开发者_如何学JAVA = employeesRepository;
    }

    //...
}


Does your AdminController have a parameterless constructor?


Yes, you'll need to have a parameterless constructor. If you are trying to inject dependencies you'll need to write or use a controller factory which knows how to do this.

This may help:

Constructor Dependency Injection in a ASP.NET MVC Controller

0

精彩评论

暂无评论...
验证码 换一张
取 消