我在项目中使用Singleton。我的代码有意义吗?具体来说这行:
public UserRepository User => new UserRepository();
UserRepository
实现了反射添加,编辑和删除等功能。
internal sealed class DataManager
{
public UserRepository User => new UserRepository();
private static DataManager _active = null;
private static object _syncRoot = new object();
public static DataManager Instance
{
get
{
lock (_syncRoot)
if (_active == null)
_active = new DataManager();
return _active;
}
}
}