Skip to content

Commit

Permalink
优化分布式Id生成器自动注册机器码
Browse files Browse the repository at this point in the history
  • Loading branch information
zhontai committed Mar 15, 2024
1 parent 29bb711 commit f0f2da4
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static void AddIdGenerator(this IServiceCollection services)
if (_isSet)
throw new InvalidOperationException("只允许添加一次Id生成器");

Task.Delay(new Random().Next(10, 100)).Wait();

SetIdGenerator(idGeneratorConfig);

_isSet = true;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/ZhonTai.Admin/Core/HostApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private void ConfigureServices(IServiceCollection services, IWebHostEnvironment
services.AddSingleton<ICacheTool, RedisCacheTool>();
//分布式Redis缓存
services.AddSingleton<IDistributedCache>(new DistributedCache(redis));
//分布式雪花漂移Id
//分布式Id生成器
services.AddIdGenerator();
}
else
Expand All @@ -320,7 +320,7 @@ private void ConfigureServices(IServiceCollection services, IWebHostEnvironment
services.AddSingleton<ICacheTool, MemoryCacheTool>();
//分布式内存缓存
services.AddDistributedMemoryCache();
//雪花漂移Id
//Id生成器
YitIdHelper.SetIdGenerator(appConfig.IdGenerator);
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/ZhonTai.Admin/ZhonTai.Admin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<PackageReference Include="Castle.Core.AsyncInterceptor" Version="2.1.0" />
<PackageReference Include="DotNetCore.CAP" Version="8.0.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="FreeRedis" Version="1.2.13" />
<PackageReference Include="FreeRedis" Version="1.2.14" />
<PackageReference Include="FreeRedis.DistributedCache" Version="1.2.5" />
<PackageReference Include="FreeSql" Version="3.2.815" />
<PackageReference Include="FreeSql.Cloud" Version="1.8.3" />
Expand Down
2 changes: 1 addition & 1 deletion src/platform/ZhonTai.Common/ZhonTai.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.3" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/tests/ZhonTai.Tests/ZhonTai.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net8.0' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit f0f2da4

Please sign in to comment.