I have asp.net MVC project customized to work for one customer only.
I need to extend the project to work with as many customers as needed.
Each customer can decide if to turn some functionality on or off (defined in DB the first time a new customer is added)
I wonder what the best approach is:
1) using a base controller that contains the basic functionality required and add a new controller (for each new customer) that extends the base controller.
2) use only one controller and build each customer with factory method pattern (each customer has its own concrete classes).
3) use only one controller that holds all the functionality and turn functionality on or off depending on DB switches (defined in DB the first time a new customer is added)
thanks
All of these approaches are too restrictive and, after a certain number of new customers, you'll either be copying code all over the place or working around code you don't need for one customer but do for another.
You'd be better off implementing each customer's specific requirements as generic, reusable options. For example, if one customer has a billing section, don't create a ThatCustomerController with a billing section, instead, add the role for billing, add a billing controller, then restrict access to the controller by that role.
It may feel like more complex work right now, but in a year's time you'll be thankful for the flexibility.
Very rough pseudo code example:
public class GeneralController : Controller
{
public ActionResult Index()
{
// Everyone can come here
}
}
[Authorize(Roles = "Billing")]
public class BillingController : Controller
{
public ActionResult Index()
{
// Only those with the 'billing' role can come here
}
}