I'm working on a controller that is a part of a very flat hierarchy of pages, and it looks like one section of the site could have over a dozen action methods, not including their corresponding post actions. Is there a good way to break this controller up while still preserving the section name? I don't want that controller class getting out of control.
views:
83answers:
4If your controller class is getting out of control on a dozen actions, you might want to rethink how much logic should be in there and how much can be refactored out into services.
Also, if your controller is getting up to much more than a dozen actions, you might want to consider whether it can be broken down into separate controllers. Remember, you can change the routing rules and controller factory such that the URL remains the same but the controller is broken up.
If you're comfortable that you've done what you can and still want to break it into separate files - use a partial class.
If I understand correctly, you just want to split a class across multiple files so each file is easier to understand.
That would mean you want to use Partial Classes. They allow you to split the definition of a single class across multiple files.
is it a good practice to use hierarchical classes of controllers instead of using partial classes?
e.g. if a reference data view is same for multiple entities then may i can use a base class that just loads the view and my drive classes load the data for each entity itself?
... base controller class
public class BaseREFDATAController{
public void LoadsView() { load view logic }
}
Drived class
public Class REFDATAController: BaseREFDATAController {
public void LoadAccountTypeData()
{ load data logic }
public void LoadCustomerTypeData()
{ load data logic }
}
some expert opinions required??
-ar