我在.NET中创建了一个Registry类,它是单例的。显然这个单例的行为就像被保存在缓存中一样(每个会话都可以访问单例对象)。这是一个好的实践还是应该将此单例添加到缓存中?同时,我需要注意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;
}
}
}