单例模式
public class BaseSingleton { static BaseSingleton() { AllSingletons = new Dictionary<Type, object>(); } /// <summary> /// Dictionary of type to singleton instances. /// </summary> public static IDictionary<Type, object> AllSingletons { get; set; } } public class Singleton<T> : BaseSingleton { private static T instance; /// <summary> /// The singleton instance for the specified type T. Only one instance (at the time) of this object for each type of T. /// </summary> public static T Instance { get { return instance; } set { instance = value; AllSingletons[typeof(T)] = value; } } } public class QueueSingleton { public static WeiXinRechargeBLL Create() { //create NopEngine as engine return Singleton<WeiXinRechargeBLL>.Instance ?? (Singleton<WeiXinRechargeBLL>.Instance = new WeiXinRechargeBLL()); } }