I've declared an event on an HTTP Module so it will poll subscribers for a true/false value to determine if it should go ahead with its task of tweaking the HTTP Response. If only one subscriber answers true then it runs its logic.
Does this make sense?
Are there potential pitfalls I'm not seeing?
public class ResponseTweaker : IHttpModule {
// to be a list of subscribers
List<Func<HttpApplication, bool>> listRespondants = new List<Func<HttpApplication, bool>>();
// event that stores its subscribers in a collection
public event Func<HttpApplication, bool> RequestConfirmation {
add {
listRespondants.Add(value);
}
remove {
listRespondants.Remove(value);
}
}
public void Init(HttpApplication context) {
if (OnGetAnswer(context)) // poll subscribers ...
// Conditionally Run Module logic to tweak Response ...
}
/* Method that polls subscribers and returns 'true'
* if only one of them answers yes.
*/
bool OnGetAnswer(HttpApplication app) {
foreach (var respondant in listRespondants)
if (respondant(app))
return true;
return false;
}
// etc...
}
I don't think it is a good idea. The amount of issues would depend on some factors like...
The following can be a show stopper...
IISReset or Application Domain recycle will remove all this information from your application. How are you planning to bring the items back in this list? Database?
What if you have a Web farm. This application will not work as expected the moment you try to scale out. The reason being... even if you have the same module loaded on all the servers in the web farm the data in Worker Process is local. Hence the listRespondants would be different in all your servers unless you are loading it from some database.