1
0
mirror of synced 2026-04-04 10:38:42 +08:00

auto commit

This commit is contained in:
yitter
2024-02-05 14:57:40 +08:00
parent 33a056a47a
commit da5720b78e
20 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
/*
* 版权属于yitter(yitter@126.com)
* 开源地址https://github.com/yitter/idgenerator
* 版权协议MIT
* 版权说明:只要保留本版权,你可以免费使用、修改、分发本代码。
* 免责条款:任何因为本代码产生的系统、法律、政治、宗教问题,均与版权所有者无关。
*
*/
using System;
using System.Collections.Generic;
using System.Text;
namespace Yitter.IdGenerator
{
/// <summary>
/// 这是一个调用的例子,默认情况下,单机集成者可以直接使用 NextId()。
/// </summary>
public class YitIdHelper
{
private static IIdGenerator _IdGenInstance = null;
public static IIdGenerator IdGenInstance => _IdGenInstance;
/// <summary>
/// 设置参数,建议程序初始化时执行一次
/// </summary>
/// <param name="options"></param>
public static void SetIdGenerator(IdGeneratorOptions options)
{
_IdGenInstance = new DefaultIdGenerator(options);
}
/// <summary>
/// 生成新的Id
/// 调用本方法前,请确保调用了 SetIdGenerator 方法做初始化。
/// </summary>
/// <returns></returns>
public static long NextId()
{
//if (_IdGenInstance == null)
//{
// lock (_IdGenInstance)
// {
// if (_IdGenInstance == null)
// {
// _IdGenInstance = new DefaultIdGenerator(
// new IdGeneratorOptions() { WorkerId = 0 }
// );
// }
// }
//}
if (_IdGenInstance == null) throw new ArgumentException("Please initialize Yitter.IdGeneratorOptions first.");
return _IdGenInstance.NewLong();
}
}
}