HuanMengAdmin/admin-server/MiaoYu.Core/CoreStartup.cs
2024-07-18 02:27:50 +08:00

51 lines
2.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

namespace MiaoYu.Core;
/// <summary>
/// 程序启动器
/// </summary>
[ImportStartupModule(
typeof(CoreAutoRegisterIOCStartup)
)]
public class CoreStartup : StartupModule<CoreStartup>
{
/// <summary>
/// 程序启动器
/// </summary>
public CoreStartup() => Order = -1;
/// <summary>
///
/// </summary>
/// <param name="webApplicationBuilder"></param>
public override void ConfigureServices(WebApplicationBuilder webApplicationBuilder)
{
webApplicationBuilder.Services.AddIdGen(0);
// MemoryCache
webApplicationBuilder.Services.AddMemoryCache();
}
/// <summary>
///
/// </summary>
/// <param name="webApplication"></param>
public override void Configure(WebApplication webApplication)
{
// 创建 IdGeneratorOptions 对象,可在构造函数中输入 WorkerId
var options = new Yitter.IdGenerator.IdGeneratorOptions((ushort)Thread.CurrentThread.ManagedThreadId);
options.DataCenterIdBitLength = 0; // 默认值0不用设置。若要使用则设置为5表示5bit的数据中心Id支持最多部署32个数据中心。
options.WorkerIdBitLength = 12; // 默认值6限定 WorkerId 最大值为2^6-1即默认最多支持64个节点。
options.SeqBitLength = 10; // 默认值6限制每毫秒生成的ID个数。若生成速度超过5万个/秒,建议加大 SeqBitLength 到 10。
// options.BaseTime = Your_Base_Time; // 如果要兼容老系统的雪花算法此处应设置为老系统的BaseTime。
// ...... 其它参数参考 IdGeneratorOptions 定义。
// 配置长度
// 保存参数(务必调用,否则参数设置不生效):
//options.DataCenterId = 2;
YitIdHelper.SetIdGenerator(options);
//var id = YitIdHelper.NextId();
}
}