using System; namespace IFramework.Singleton { /// /// 单例基类 /// /// public abstract class Singleton : Unit, ISingleton where T : Singleton { private static T _instance; static object lockObj = new object(); /// /// 实例 /// public static T instance { get { lock (lockObj) if (_instance == null) { _instance = SingletonCreator.CreateSingleton(); SingletonCollection.Set(_instance); } return _instance; } } /// /// ctror /// protected Singleton() { } /// /// 初始化 /// protected virtual void OnSingletonInit() { } /// /// 注销 /// public override void Dispose() { base.Dispose(); if (!disposed) { _instance = null; } } void ISingleton.OnSingletonInit() { OnSingletonInit(); } } }