NopCommerce(EBuy模拟)中Singleton单例的设计——泛型学习
来源:互联网 发布:linux中dump命令 编辑:程序博客网 时间:2024/05/22 06:46
/// <summary> /// Provides access to all "singletons" stored by <see cref="Singleton{T}"/>. /// Singleton中包含一个键为类型,值为该类型的实例的一个Dictionary /// </summary> public class Singleton { static Singleton() { allSingletons = new Dictionary<Type, object>(); } static readonly IDictionary<Type, object> allSingletons; /// <summary>Dictionary of type to singleton instances.</summary> public static IDictionary<Type, object> AllSingletons { get { return allSingletons; } } }
/// <summary> /// A statically compiled "singleton" used to store objects throughout the /// lifetime of the app domain. Not so much singleton in the pattern's /// sense of the word as a standardized way to store single instances. /// Singleton<T>中包含一个T的实例,并存入类实例字典中 /// </summary> /// <typeparam name="T">The type of object to store.</typeparam> /// <remarks>Access to the instance is not synchrnoized.</remarks> public class Singleton<T> : Singleton { 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; } } } /// <summary> /// Provides a singleton list for a certain type. /// SingletonList<T>中包含一个Singleton<IList<T>>实例 /// </summary> /// <typeparam name="T">The type of list to store.</typeparam> public class SingletonList<T> : Singleton<IList<T>> { static SingletonList() { Singleton<IList<T>>.Instance = new List<T>(); } /// <summary>The singleton instance for the specified type T. Only one instance (at the time) of this list for each type of T.</summary> public new static IList<T> Instance { get { return Singleton<IList<T>>.Instance; } } } /// <summary> /// Provides a singleton dictionary for a certain key and vlaue type. /// SingletonDictionary<TKey, TValue>中包含一个Singleton<Dictionary<TKey, TValue>>实例 /// </summary> /// <typeparam name="TKey">The type of key.</typeparam> /// <typeparam name="TValue">The type of value.</typeparam> public class SingletonDictionary<TKey, TValue> : Singleton<IDictionary<TKey, TValue>> { static SingletonDictionary() { Singleton<Dictionary<TKey, TValue>>.Instance = new Dictionary<TKey, TValue>(); } /// <summary>The singleton instance for the specified type T. Only one instance (at the time) of this dictionary for each type of T.</summary> public new static IDictionary<TKey, TValue> Instance { get { return Singleton<Dictionary<TKey, TValue>>.Instance; } } }
0 0
- NopCommerce(EBuy模拟)中Singleton单例的设计——泛型学习
- NopCommerce(EBuy模拟)中类型查找接口ITypeFinder的设计——反射+泛型
- NopCommerce中(EBuy模拟)AutoMap的使用
- NopCommerce中(EBuy模拟)Autofac容器的使用框架
- Java设计模式学习之 —— 单例(Singleton)
- 设计模式学习笔记——单例(Singleton)模式
- 设计模式学习笔记—单例模式(Singleton)
- 菜鸟的学习之路(6) — 设计模式之单例模式(Singleton)
- 设计模式——单例Singleton
- 设计模式——单例Singleton
- 单例设计模式——singleton
- Java设计模式—singleton 单例
- 设计模式学习(创建型模式)—单例模式(Singleton)
- 我的设计模式学习笔记------>单例模式(Singleton)
- Cocoa的单例(singleton)设计模式
- Java的单例设计模式Singleton
- 设计模式————单例模式Singleton
- JAVA设计模式——单例(Singleton)模式
- C#字符串的用法
- 初探JNI学习笔记
- could not find a getter for ... in class ... 异常的原因解析
- 从printf谈可变参数函数的实现
- 思科CCNA第二学期期末考试答案
- NopCommerce(EBuy模拟)中Singleton单例的设计——泛型学习
- linux grep命令详解
- Windows 7注册表键值的权限问题以及提升权限的方法
- fscanf函数和memcopy函数,memmove函数
- Linux负载均衡软件LVS之一(概念篇)
- git log常用命令以及技巧
- 带有一个UITextView的AlertView
- 伸展树uva11996
- AlphaBeta剪枝算法