SqlSugar/Src/Asp.NetCore2/SqlSugar/DistributedSystem/Snowflake/SnowFlakeSingle.cs
2022-03-25 10:39:07 +08:00

46 lines
856 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public sealed class SnowFlakeSingle
{
private static object LockObject = new object();
private static DistributedSystem.Snowflake.IdWorker worker;
public static int WorkId = 1;
public static int DatacenterId = 1;
private SnowFlakeSingle()
{
}
static SnowFlakeSingle() { }
public static DistributedSystem.Snowflake.IdWorker Instance
{
get
{
if (worker == null)
{
lock (LockObject)
{
if (worker == null)
{
worker = new DistributedSystem.Snowflake.IdWorker(WorkId, DatacenterId);
}
}
}
return worker;
}
}
public static DistributedSystem.Snowflake.IdWorker instance
{
get
{
return Instance;
}
}
}
}