优化雪花配置代码
This commit is contained in:
parent
5d48eebc2c
commit
ea5dedd06d
@ -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服务器
|
||||||
|
|||||||
@ -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())
|
|
||||||
{
|
|
||||||
YitIdHelper.SetIdGenerator(snowIdOpt);
|
|
||||||
SnowFlakeSingle.WorkId = snowIdOpt.WorkerId;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
services.AddYitIdHelper(snowIdOpt);
|
services.AddYitIdHelper(snowIdOpt);
|
||||||
}
|
|
||||||
|
|
||||||
StaticConfig.CustomSnowFlakeFunc = () =>
|
StaticConfig.CustomSnowFlakeFunc = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user