SnowflakeIdServiceExtension.cs 595 B

12345678910111213141516171819
  1. using Furion;
  2. using Microsoft.Extensions.DependencyInjection;
  3. using Yitter.IdGenerator;
  4. namespace YBEE.EQM.Web.Core
  5. {
  6. /// <summary>
  7. /// 雪花ID
  8. /// </summary>
  9. internal static class SnowflakeIdServiceExtension
  10. {
  11. public static void AddSnowflakeId(this IServiceCollection services)
  12. {
  13. // 设置雪花Id的workerId,确保每个实例workerId都应不同
  14. var workerId = ushort.Parse(App.Configuration["SnowId:WorkerId"] ?? "1");
  15. YitIdHelper.SetIdGenerator(new IdGeneratorOptions { WorkerId = workerId });
  16. }
  17. }
  18. }