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.
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 any开发者_如何学运维one recommend on any reading material about plugin systems?
Anything specifically on web environments would be most appreciated.If you want to keep with the current extension system design, I would go to implementing a custom EventArgs class specific to each of your events. In this manner you can pass along various configuration, or simply identification data.
Your extension providers then can take action based on the passed information. For example, they could configure to only respond to specific forums, etc.
精彩评论