我正在创建一个需要在 ASP.NET 请求生命周期的各个阶段运行一些代码的库。
通过重写 HttpApplication.Init() 并在其中注册各种处理程序来编写 Web 应用程序时,很容易做到这一点。
但是,我想在 Application_Start(); 期间从我的库中执行此操作;我不想让消费者不得不重写 Init() 并从那里调用我的事件设置代码。
有什么办法可以做到这一点?
这是我的理想设置:
// in the consumer's code
protected void Application_Start()
{
// should ideally be able to register lifecycle event handlers from the line below
MyLibrary.Configure(...);
}