views:

66

answers:

2

Hello,

I have been reading about "Fat Controllers" but most of the articles out there focus on pulling the service/repository layer logic out of the controller. However, I have run into a different situation and am wondering if anyone has any ideas for improvement.

I have a controller with too many actions and am wondering how I can break this down into many controllers with fewer actions. All these actions are responsible for inserting/updating/removing objects that all belong to the same aggregate. So I'm not quiet keen in having a seperate controller for each class that belongs to this aggregate...

To give you more details, this controller is used in a tabbed page. Each tab represents a portion of the data for editing and all the domain model objects used here belong to the same aggregate.

Any advice?

Cheers, Mosh

A: 

For all your tabs you can use one action, that have an tab parameter, that indicate what data you need to return.

The controller job is to cast this string tab into enum type variable. Then the tab will be send to the repository, and the repository job is to return data in response to the tab value.

The controller should do its job through to services: Input Validator and Mapper.

The mapper service job is to map the user input (typically strings) into actual typed value (int, System.DateTime, enum types, etc).

The validator job is to check that the input is valid.

Following this principles should keep your controllers really tiny.

Mendy
This is not quiet achieviable as each tab returns different results to the user. So if I combine all ViewXXXTab actions into 1, then I'll have a method with lots of conditation statements to decide what method to call to fetch data. For example:switch (tab){ case A: Call SomeObject.SomeMethod(); case B: Call AnotherObject.AnotherMethod(); case C: ... ...}
Mosh
A: 

If you wanted something simple and easy I'd suggest just splitting up the controller into partial classes based on the tabs. Of course, it's still a fat controller there's just some obvious separation between the various tab functionalities.

Spencer Ruport