WebActivatorEx
WebActivator类库提供了3种功能:
-
PreApplicationStartMethod
- PostApplicationStartMethod
-
ApplicationShutdownMethod
这三种功能分别在HttpApplication初始化之前、之后以及ShutDown的时候分别执行指定的代码
示例如下:
[assembly: WebActivator.PreApplicationStartMethod(typeof(A.InitClass1), "PreStart")] [assembly: WebActivator.PostApplicationStartMethod(typeof(A.InitClass1), "PostStart")] [assembly: WebActivator.ApplicationShutdownMethod(typeof(A.InitClass1), "ShutDown")]
另外还有一点和系统自带的PreApplicationStartMethodAttribute不同的是,WebActivator的每种特性都可以使用多次,比如:
[assembly: WebActivator.PreApplicationStartMethod(typeof(A.InitClass1), "PreStart")] [assembly: WebActivator.PreApplicationStartMethod(typeof(A.InitClass2), "PreStart")] [assembly: WebActivator.PreApplicationStartMethod(typeof(A.InitClass3), "PreStart")]
想了解WebActivator的实现原理,请参考大佬的详细介绍 https://blog.csdn.net/weixin_33883178/article/details/85631825