1

As the title states, I'm looking for a way to organize code with various customer "settings" that control program logic and sometimes display logic without introducing a nest of if/else branches in both the client (javascript) and the server (C#).

What mechanisms do I have to choose from for making a series of modules used for validation, field visibility, processing rules and such that can be loaded dynamically based on, say, a username or other bit of customer data? I am aware of IOC, I need something more specific than "configurable modules". Are there libraries out there to provide a structure for organizing code and loading it conditionally?

What about in javascript? Are there well-known mechanisms for dynamically loading javascript from small files to be executed conditionally?

Most of all, is there a name for what I'm describing? I don't want a rules engine or decision engine where the code is stored as a set of values and operators. I want to keep the code in its original files. I also want to use strong typing and interfaces where I can.

Any ideas?

Chris McCall
  • 10,317
  • 8
  • 49
  • 80

2 Answers2

1

You should look at either (or both) of

Here's the MSDN docs on the System.Addin namespace(s) as well: http://msdn.microsoft.com/en-us/library/gg145020.aspx

This discussion talks about the difference between MEF and System.Addin: Choosing between MEF and MAF (System.AddIn)

The wiring and configuration of your extension system is of course highly domain specific.

Good Luck!

Community
  • 1
  • 1
Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135
0

If you wish to use strong typing and interfaces, then why not just go that route? You could create an interface that defines callable methods for your individual customer logic, and then create the implementation classes for each. That way you would only have one piece of conditional logic, perhaps a switch statement, in your system startup routine that loads the correct implementation.

Jason
  • 1
  • I don't want to switch over which implementation of the entire system to load. I want to be able to place arbitrary extensibility points throughout. I also don't want to manage the catalog, manifests, metadata, etc. IOC was invented to solve these very problems. – Chris McCall Sep 08 '11 at 15:41
  • Well, I didn't mean to imply that you would need to provide a different implementation of the entire system, merely the parts that support differentiation of logic. Speaking of IOC, you could well employ the factory design principle. Instead of using an interface, create an abstract base class with overridable default properties and methods that are inherited by your customer implementation objects. For example, a boolean property could be used to control field visibility. The extensibility points you mentioned are simply where the base class is resolved to the loaded object's implementation. – Jason Sep 08 '11 at 17:34