我已经在 HTTP 模块上声明了一个事件,因此它将轮询订阅者的真/假值,以确定它是否应该继续执行调整 HTTP 响应的任务。如果只有一个订阅者回答为真,那么它就会运行它的逻辑。
这有意义吗?
是否有我没有看到的潜在陷阱?
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...
}