Kon*_*rin 11 c# static assemblies initialization
我的程序集中有很多入口点,我希望在运行此程序集中的任何其他代码之前,每个AppDomain执行一次初始化代码.最好的方法是什么?
我看到的一个解决方案是拥有一个带有静态构造函数的类,并继承我拥有的每个入口点.像这样的东西:
public class Initializer
{
static Initializer()
{
EnsureInitialized(); // Calls initialization code once and only once
}
}
public class EntryPointOne : Initializer, IEntryPoint
{
// Some code here
}
public class EntryPointTwo : Initializer, IEntryPoint
{
// Some code here
}
// etc.
Run Code Online (Sandbox Code Playgroud)
这让我可以避免在每个入口点编写样板静态构造函数,但是没有多继承,这并不总是可行的.你能想到其他更好的选择吗?
| 归档时间: |
|
| 查看次数: |
3234 次 |
| 最近记录: |