Browse Source

feat: 添加redis分布式锁

fix-permisson
Hanpaopao 2 years ago
parent
commit
1c5905d12a
  1. 1
      aspnet-core/Directory.Build.Volo.targets
  2. 5
      aspnet-core/Directory.Build.targets
  3. 19
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs
  4. 6
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs
  5. 2
      aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj

1
aspnet-core/Directory.Build.Volo.targets

@ -89,5 +89,6 @@
<PackageReference Update="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="8.3.3"/> <PackageReference Update="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="8.3.3"/>
<PackageReference Update="Volo.Abp.EventBus" Version="8.3.3"/> <PackageReference Update="Volo.Abp.EventBus" Version="8.3.3"/>
<PackageReference Update="Volo.Abp.Localization" Version="8.3.3" /> <PackageReference Update="Volo.Abp.Localization" Version="8.3.3" />
<PackageReference Update="Volo.Abp.DistributedLocking" Version="8.3.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

5
aspnet-core/Directory.Build.targets

@ -91,5 +91,10 @@
<PackageReference Update="NEST" Version="7.17.5"/> <PackageReference Update="NEST" Version="7.17.5"/>
<PackageReference Update="WebApiClientCore" Version="2.1.4" /> <PackageReference Update="WebApiClientCore" Version="2.1.4" />
<!-- redis分布式锁-->
<PackageReference Update="DistributedLock.Redis" Version="1.0.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>

19
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.Configure.cs

@ -1,4 +1,7 @@
namespace Lion.AbpPro; using Medallion.Threading;
using Medallion.Threading.Redis;
namespace Lion.AbpPro;
public partial class AbpProHttpApiHostModule public partial class AbpProHttpApiHostModule
{ {
@ -270,4 +273,18 @@ public partial class AbpProHttpApiHostModule
{ {
Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsEnabled; }); Configure<AbpMultiTenancyOptions>(options => { options.IsEnabled = MultiTenancyConsts.IsEnabled; });
} }
/// <summary>
/// 配置redis分布式锁
/// </summary>
private void ConfigurationDistributedLocking(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var connectionString = configuration.GetValue<string>("Redis:Configuration");
context.Services.AddSingleton<IDistributedLockProvider>(sp =>
{
var connection = ConnectionMultiplexer.Connect(connectionString);
return new RedisDistributedSynchronizationProvider(connection.GetDatabase());
});
}
} }

6
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/AbpProHttpApiHostModule.cs

@ -1,3 +1,5 @@
using Volo.Abp.DistributedLocking;
namespace Lion.AbpPro namespace Lion.AbpPro
{ {
[DependsOn( [DependsOn(
@ -12,7 +14,8 @@ namespace Lion.AbpPro
typeof(AbpProCapModule), typeof(AbpProCapModule),
typeof(AbpProCapEntityFrameworkCoreModule), typeof(AbpProCapEntityFrameworkCoreModule),
typeof(AbpAspNetCoreMvcUiBasicThemeModule), typeof(AbpAspNetCoreMvcUiBasicThemeModule),
typeof(AbpCachingStackExchangeRedisModule) typeof(AbpCachingStackExchangeRedisModule),
typeof(AbpDistributedLockingModule)
//typeof(AbpBackgroundJobsHangfireModule) //typeof(AbpBackgroundJobsHangfireModule)
)] )]
public partial class AbpProHttpApiHostModule : AbpModule public partial class AbpProHttpApiHostModule : AbpModule
@ -28,6 +31,7 @@ namespace Lion.AbpPro
{ {
var configuration = context.Services.GetConfiguration(); var configuration = context.Services.GetConfiguration();
ConfigureCache(context); ConfigureCache(context);
ConfigurationDistributedLocking(context);
ConfigureSwaggerServices(context); ConfigureSwaggerServices(context);
ConfigureJwtAuthentication(context, configuration); ConfigureJwtAuthentication(context, configuration);
//ConfigureHangfire(context); //ConfigureHangfire(context);

2
aspnet-core/services/host/Lion.AbpPro.HttpApi.Host/Lion.AbpPro.HttpApi.Host.csproj

@ -40,6 +40,8 @@
<PackageReference Include="MiniProfiler.EntityFrameworkCore" /> <PackageReference Include="MiniProfiler.EntityFrameworkCore" />
<PackageReference Include="MiniProfiler.Shared" /> <PackageReference Include="MiniProfiler.Shared" />
<PackageReference Include="Volo.Abp.BackgroundJobs.HangFire" /> <PackageReference Include="Volo.Abp.BackgroundJobs.HangFire" />
<PackageReference Include="Volo.Abp.DistributedLocking"/>
<PackageReference Include="DistributedLock.Redis"/>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save