SingletonTEntity 类

泛型单例基类,为派生类提供线程安全的单例模式实现。

Definition

命名空间: Suresking.Utility
程序集: Suresking.Utility (在 Suresking.Utility.dll 中) 版本:1.3.22+a27276bb8ffde055e69ff608e98aafba279e1e99
C#
public abstract class Singleton<TEntity>
where TEntity : class
Inheritance
Object    SingletonTEntity

类型参数

TEntity
单例类型,必须是派生自 Singleton{TEntity} 的类。

备注

使用要求:

派生类必须提供 SingletonTEntity 作为基类,并且必须有且仅有一个私有的无参构造函数。

使用示例:

public sealed class MyService : Singleton<MyService> { private MyService() { // 初始化代码 } public void DoSomething() { Console.WriteLine("Doing something..."); } } // 使用 MyService.Instance.DoSomething();

构造函数

SingletonTEntity初始化 SingletonTEntity 类的一个新实例

属性

Instance 获取单例实例。首次访问时会自动创建实例。

参见