Hi all,
Before I ask the question, here is my understanding about Controller in MVC pattern.
- Controller is Application Layer (in DDD)
- It controls Application flow.
- It is kept thin
- It controls unit of work (a.k.a Transaction)
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?
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
- 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)
Thanks in advance.