Hey SO,
I am wondering what's the best way to insert customization hooks into my application. Basically, my application is split into two assemblies: A Core
assembly containing all the business logic and a UserInterface
assembly containing the GUI, controller classes (I am using a deviant MVC pattern callse "Passive View") and some helper classes. The core assembly is used by some other applications as well.
My application is used by our company to handle orders from other companies. The general process is the same for all companies, but there are small deviations here and there that are customer-specific. As of now those deviations are implemented straight into the core assembly, which smells. I want to separate those specifics, best encapsualte them into a single object per customer so I have a central object containing all customer specific details which I can put into the UserInterface assembly.
I thought about using events to achieve this. By adding some events in my core classes, my controller classes would be able to subsribe or unsubscribe methods implementing those deviations for certain customers.
I can think of two ways of doing this: Adding those bindings manually or let them being added automatically, if the deviant methods exist. I'm thinking about something like this for the latter:
foreach (Order order in form.SelectedOrders) {
CustomerExtension customer = customerExtensions[order.Customer];
if(Exists(customer.StatusChanging(...)) // Pseudo Code!
OrderManager.StatusChanging += new StatusChangingEventHandler(customer.StatusChanging(...));
order.SetStatus(newStatus);
if(Exists(customer.StatusChanging(...)) // Pseudo Code!
OrderManager.StatusChanging -= new StatusChangingEventHandler(customer.StatusChanging(...));
}
I guess I have to use Reflection to achieve this, but is this viable for operations that need to be done many times?
Or are there better ways to add customization hooks while leting me centralize the deviations on a customers-basis?
[EDIT] Completely revised the question.