DLL 命名空间中的 MVC 控制器
目前,我的控制器和视图位于单独的 DLL 中。
当我创建新控制器时,我必须更新我的命名空间以匹配它在我的 Web 项目中的位置。
我希望我的控制器具有不同的命名空间,但是如果我更改命名空间,我会收到 404 错误..
我会给出一个例子..
我有一个控制器,
namespace MyWebSite.Web.Mvc.Areas.Member.Controllers { }
我想将其更改为
namespace MyWebSite.DLL.Mvc.Areas.Member.Controllers { }
但这并不不工作.. 如何更改我的命名空间并使其仍然有效?
Currently I have my Controllers and Views inside a separate DLL
When I create a new controller, I'm having to update my namespace to match how it is going to be in my web project.
I'd like my controllers with a different namespace, but if i change my namespace, I'm getting 404 errors..
I'll give an example..
I have a controller at
namespace MyWebSite.Web.Mvc.Areas.Member.Controllers { }
I'd like to change it to
namespace MyWebSite.DLL.Mvc.Areas.Member.Controllers { }
But this doesn't work..
How can I change my namespace and still have it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
据我所知,在一个简单的 MVC 项目中,由于 MVC 使用的约定模型编码,mvc 运行时将始终默认为该应用程序的正常控制器名称空间。
然而,这并不是说你的尝试是不可能的。
为了使用不同的命名空间,我认为理想情况下您需要查看 .NET 4 中内置的 MEF 功能之类的东西,或者您需要使用 IOC 容器,例如 Unity/Structuremap 或许多其他可用的容器之一。
我们至少有一个有关使用构建块构建 MVC 应用程序的有关 litnug 的演示文稿,可以在以下位置的 archves 中找到该演示文稿:
并且在channel9.msdn.com 上有很多来自以前的 PDC 和其他 MS 开发会议的演示文稿。
As far as I'm aware in a bare bones MVC project, the mvc runtime will always default to the normal controller name space for that app beacuse of the coding to convention model that MVC uses.
However, thats not to say what your trying to attempt is not possible.
In order to use different namespaces, I think ideally you need to be looking at something like the MEF functionanlity built into .NET 4, or you need to be using an IOC container such as Unity/Structuremap or one of the many others available.
We have at least one presentation on lidnug about building MVC apps using building blocks, which can be found in the archves at:
and there's quite a few available on channel9.msdn.com from previous PDC and other ms dev conferences.