简体   繁体   English

我可以覆盖PreApplicationStartMethodAttribute吗?

[英]Can I override PreApplicationStartMethodAttribute?

Many libraries nowadays auto-register/start using the PreApplicationStartMethodAttribute approach . 如今,许多库都使用PreApplicationStartMethodAttribute方法自动注册/启动。

I don't like it. 我不喜欢 I want to control when the init code is run, for a variety of reasons. 由于多种原因,我想控制何时运行初始化代码。 In many cases, I'd like to call init code myself from Application_Start . 在许多情况下,我想自己从Application_Start调用初始化代码。

Is there some way for me to intercept these calls and stop them? 我有什么办法可以拦截这些电话并阻止它们吗?

I doubt you could stop all uses of this mechanism, because it would go counter to one of the fundamental purposes of the mechanism: to allow libraries and plugins to hook into the initialization phase and run their own initialization code, without the need for placing initialization code manually--to enable those libraries autonomous control of their initialization. 我怀疑您是否可以停止使用此机制,因为它会违背该机制的基本目的之一:允许库和插件挂接到初始化阶段并运行自己的初始化代码,而无需放置初始化手动编写代码-使这些库能够自主控制其初始化。

Let's consider what would happen if it were possible to shut off this mechanism: it would break libraries that depend on it for their initialization to execute early in the startup, earlier than Application_Start. 让我们考虑一下,如果有可能关闭该机制,将会发生什么情况 :它将破坏依赖于它进行初始化的库,以便在启动时早于Application_Start执行。 It would also break libraries that don't document or specify a way for users to initialize the library manually. 它还会破坏没有记录的库,或者为用户指定手动初始化库的方式。

I'm afraid the mechanism is meant to guarantee the opposite of what you wish to accomplish. 恐怕该机制是为了保证与您希望实现的目标相反。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM