Before asking a question, here is my understanding of the controller in the MVC pattern.
- The controller is the application level (in DDD)
- It controls the flow of applications.
- He stays thin
- He controls the unit of work (aka Transaction)
My question is, " when should I create a new controller class? ". I will give an example of DinnerController in NerdDinner .
- Is this a controller for the Dinner Module ? (Is this a module? IMO, it's too small for a module)
- If so, should I create a controller for each module ? And the controller will become thick?
- If this is not the case, when should I create a new controller?
I personally prefer to create a Controller class for use case . For example, CreateDinnerControllelr, EditDinnerController, ListDinnerController, SearchDinnerController, etc. But there are a few drawbacks to IMO, such as
- Sometimes it violates the DRY principle (it may be necessary to create the same ViewModel in two places, for example, Create and Edit may have a DinnerViewModel)
- Need to explicitly define routing? (I'm still sorting through the route as / Dinner / Create, / Dinner / Editing / 1)
Thanks in advance.
source
share