问题描述
结果
之前,我问的问题,下面是我对控制器在MVC模式的理解。
Before I ask the question, here is my understanding about Controller in MVC pattern.
- 控制器是应用层(DDD)
- 它控制应用程序流。
- 这是保持薄
- 它控制工作(a.k.a交易)单位
我的问题是:时,我应该创造新的控制器类?。我要在的一个例子是DinnerController。
My question is "when should I create new Controller class?". I'll take an example as DinnerController in NerdDinner.
- 难道是控制器的晚餐模块? (它是模块?海事组织,它是模块太小)
- 如果是这样,我应该创建控制器每个模块?并且将在控制发胖?
- 如果不是的话,应该在创建新的控制器?
- Is it the controller for Dinner Module? (Is it module? IMO, it is too small for module)
- If it is, should I create controller for each module? And will the controller become fat?
- If it is not, when should I create new controller?
我个人preFER每使用情况创建控制器类。例如,CreateDinnerControllelr,EditDinnerController,ListDinnerController,SearchDinnerController等,但也有一些缺点,国际海事组织,如
I personally prefer to create Controller class per use case. For example, CreateDinnerControllelr, EditDinnerController, ListDinnerController, SearchDinnerController, etc. But there are a few drawbacks IMO such as
- 有时,它违反了DRY原则(这可能需要在两个地方创建相同的视图模型,例如创建和编辑可能有DinnerViewModel)
- 需要明确定义路由? (我还是喜欢perfer路线的 /晚餐/创建的 /晚餐/编辑/ 1 的)
- Sometimes, it violates DRY principle (it might need to create the same ViewModel in two place, e.g. Create and Edit might have DinnerViewModel)
- Need to explicitly define routing? (I still perfer route like /Dinner/Create, /Dinner/Edit/1)
先谢谢了。
推荐答案
这是ASP.net MVC和轨道工作后,我觉得应该控制每资源(在 REST 创建EM>风格的应用程序)。
After working on ASP.net MVC and rails, I think Controller should create per Resource (in the REST style application).
这篇关于什么时候应该在Asp.net MVC(设计问题)创造新的控制器类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!