Hi everyone,
I'm not sure if this is an appropriate question to ask, since it is pretty specific, but anyway...
In this application I'm working on, I have an extension system based on static events. The whole idea is taken mostly from the (very cool) extension system created in BlogEngine.NET.
Essentially, on Application_Start
, an extension instance is created which hooks to static events on classes in the application.
Take for example an extension that censors blacklisted words from, say, a forum message before displaying it to the page; When a ForumMessage.OnDisplaying
event is triggered, the extension would take the ForumMessage
sender object and replace blacklisted words with gibberish.
Example:
static class WordBlackListExtension {
private static string[] _blacklist = new string[] { ... };
static WordBlacklistExtension() { ForumMessage.OnDisplaying += DoWork; }
private static void DoWork(object sender, EventArgs e) {
// Do some blacklist filtering...
((ForumMessage)sender).Body = ...;
}
}
However, since there is only one instance of each extension in the App Domain, it occurs to me this only works on a system where there is a single, system-wide configuration for each extension.
But what if I wanted per-forum or per-user control over those extensions, like in Google Labs? Per-forum blacklist, or per-user ability to enable/disable the extension?
I would have to pass additional information to the extension.
So here's the part I can't wrap my head around - Assuming I have a fairly complex object model (therefore doing something like ForumMessage.Forum.etc.Config
is bad practice);
How would you recommend to pass that information to each extension?
Should each extension retrieve its own config? Maybe pass some kind of context object through the EventArgs?
Where can I determine which forum's config to retrieve?
Can you think of a better design for this type of system?
Edit
Can anyone recommend on any reading material about plugin systems?
Anything specifically on web environments would be most appreciated.