Asp.Net MVC 注入和区域
我有一个使用 Ninject 进行依赖注入的站点,并且我在 Bootstrapper 类中定义了路由,如下所示:
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
);
}
我已向项目添加了一个区域,但默认的 AdminAreaRegistration 未注册根
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
在哪里或如何使用 Ninject 注册该区域?
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.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
Where or how do I register the Area with Ninject?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
带有源代码的示例项目现在有一个区域。看看它。 https://github.com/ninject/ninject.web.mvc/zipball/master
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
您正在调用 RegisterAllAreas() 吗?
请注意,它必须在 RegisterRoutes() 之前调用。
are you calling RegisterAllAreas()?
note it must be called before RegisterRoutes().
你解决这个问题了吗?
我遇到的问题是我的 NinjectControllerFactory 无法解析引用区域中定义的控制器的 url。我收到以下消息:
如果我将控制器移动到根 Controllers 文件夹,它将解析 url。
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:
If I move the controller to the root Controllers folder, it will resolve the url.