优化雪花配置代码

This commit is contained in:
shiningrise 2024-12-25 10:16:27 +08:00
parent 5d48eebc2c
commit ea5dedd06d
2 changed files with 10 additions and 9 deletions

View File

@ -19,6 +19,14 @@ public static class YitIdHelperExtension
public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options) public static void AddYitIdHelper(this IServiceCollection services, SnowIdOptions options)
{ {
if (App.GetConfig<CacheOptions>("Cache", true).CacheType == CacheTypeEnum.Memory.ToString())
{
YitIdHelper.SetIdGenerator(options);
SnowFlakeSingle.WorkId = options.WorkerId;
Console.WriteLine($"###########当前应用WorkId:【{options.WorkerId}】###########");
return;
}
_options = options; _options = options;
// 排除开发环境和Windows服务器 // 排除开发环境和Windows服务器

View File

@ -22,15 +22,8 @@ public static class SqlSugarSetup
{ {
// 注册雪花Id // 注册雪花Id
var snowIdOpt = App.GetConfig<SnowIdOptions>("SnowId", true); var snowIdOpt = App.GetConfig<SnowIdOptions>("SnowId", true);
if (App.GetConfig<CacheOptions>("Cache", true).CacheType == CacheTypeEnum.Memory.ToString())
{ services.AddYitIdHelper(snowIdOpt);
YitIdHelper.SetIdGenerator(snowIdOpt);
SnowFlakeSingle.WorkId = snowIdOpt.WorkerId;
}
else
{
services.AddYitIdHelper(snowIdOpt);
}
StaticConfig.CustomSnowFlakeFunc = () => StaticConfig.CustomSnowFlakeFunc = () =>
{ {