开发者

Asp.Net MVC Ninject and Areas

I have a site that uses Ninject for dependency injection and I have Routing defined within a Bootstrapper class like so:

    public void RegisterRoutes()
    {
        Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        Routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

        Routes.MapRoute(
            null,
            "{pageTitle}",
            new { controller = "Home", action = "Page", pageTitle = "Index" }
        );

        Routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }

I have added an Area to the project but the default AdminAreaRegistration is not registering the root

    public override void RegisterArea(AreaRegistrationContext context)
    {
        context.MapRou开发者_运维问答te(
            "Admin_default",
            "Admin/{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

Where or how do I register the Area with Ninject?


The sample project comming with the source code has now an area. Take a look at it. https://github.com/ninject/ninject.web.mvc/zipball/master


are you calling RegisterAllAreas()?

protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();
    RegisterRoutes(RouteTable.Routes);
}

note it must be called before RegisterRoutes().


Have you resolved this issue?

I have the problem where my NinjectControllerFactory is not resolving urls that reference controllers defined in areas. I get the following message:

The IControllerFactory 'myWebSite.WebUI.Infrastructure.NinjectControllerFactory' did not return a controller for the name 'admin'.

If I move the controller to the root Controllers folder, it will resolve the url.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜