Lie*_*oen 4 asp.net concurrency singleton caching
我在.NET中创建了一个单例的注册表类.显然,这个单例的行为就像它保存在Cache中一样(单个对象可用于每个会话).如果我将此Singleton添加到缓存中,这是一个很好的做法吗?+我是否需要使用GetInstance()函数来解决并发问题?
namespace Edu3.Business.Registry
{
public class ExamDTORegistry
{
private static ExamDTORegistry instance;
private Dictionary<int, ExamDTO> examDTODictionary;
private ExamDTORegistry()
{
examDTODictionary = new Dictionary<int, ExamDTO>();
}
public static ExamDTORegistry GetInstance()
{
if (instance == null)
{
instance = new ExamDTORegistry();
}
return instance;
}
}
}
Run Code Online (Sandbox Code Playgroud)