From 5dea4ab18ce6340666a866142ba65afc1088efd7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A9=99=E5=AD=90?= <454313500@qq.com>
Date: Sat, 1 Feb 2025 21:53:05 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E5=88=86=E5=B8=83?=
=?UTF-8?q?=E5=BC=8F=E9=94=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Yi.Framework.Rbac.Domain.csproj | 5 ++-
.../YiFrameworkRbacDomainModule.cs | 18 +++++++-
.../Services/TestService.cs | 44 ++++++++++++++++++-
3 files changed, 62 insertions(+), 5 deletions(-)
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Yi.Framework.Rbac.Domain.csproj b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Yi.Framework.Rbac.Domain.csproj
index 734dc0a1..0680e58f 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Yi.Framework.Rbac.Domain.csproj
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/Yi.Framework.Rbac.Domain.csproj
@@ -20,7 +20,10 @@
-
+
+
+
+
diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs
index a5a61d92..cb3d4bf5 100644
--- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs
+++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Domain/YiFrameworkRbacDomainModule.cs
@@ -1,6 +1,10 @@
-using Microsoft.Extensions.DependencyInjection;
+using Medallion.Threading;
+using Medallion.Threading.Redis;
+using Microsoft.Extensions.DependencyInjection;
+using StackExchange.Redis;
using Volo.Abp.AspNetCore.SignalR;
using Volo.Abp.Caching;
+using Volo.Abp.DistributedLocking;
using Volo.Abp.Domain;
using Volo.Abp.Imaging;
using Volo.Abp.Modularity;
@@ -20,7 +24,8 @@ namespace Yi.Framework.Rbac.Domain
typeof(AbpAspNetCoreSignalRModule),
typeof(AbpDddDomainModule),
typeof(AbpCachingModule),
- typeof(AbpImagingImageSharpModule)
+ typeof(AbpImagingImageSharpModule),
+ typeof(AbpDistributedLockingModule)
)]
public class YiFrameworkRbacDomainModule : AbpModule
{
@@ -36,6 +41,15 @@ namespace Yi.Framework.Rbac.Domain
//配置阿里云短信
Configure(configuration.GetSection(nameof(AliyunOptions)));
+
+ //分布式锁
+ context.Services.AddSingleton(sp =>
+ {
+ var connection = ConnectionMultiplexer
+ .Connect(configuration["Redis:Configuration"]);
+ return new
+ RedisDistributedSynchronizationProvider(connection.GetDatabase());
+ });
}
}
}
\ No newline at end of file
diff --git a/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs b/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs
index f1714368..da686753 100644
--- a/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs
+++ b/Yi.Abp.Net8/src/Yi.Abp.Application/Services/TestService.cs
@@ -1,8 +1,10 @@
using System.Xml.Linq;
using Mapster;
+using Medallion.Threading;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.RateLimiting;
using Volo.Abp.Application.Services;
+using Volo.Abp.DistributedLocking;
using Volo.Abp.Settings;
using Volo.Abp.Uow;
using Yi.Framework.Bbs.Application.Contracts.Dtos.Banner;
@@ -49,7 +51,7 @@ namespace Yi.Abp.Application.Services
throw new UserFriendlyException("业务异常");
throw new Exception("系统异常");
}
-
+
///
/// SqlSugar
///
@@ -138,6 +140,7 @@ namespace Yi.Abp.Application.Services
}
private static int RequestNumber { get; set; } = 0;
+
///
/// 速率限制
///
@@ -154,6 +157,7 @@ namespace Yi.Abp.Application.Services
public ISettingProvider _settingProvider { get; set; }
public ISettingManager _settingManager { get; set; }
+
///
/// 系统配置模块
///
@@ -175,5 +179,41 @@ namespace Yi.Abp.Application.Services
return result ?? string.Empty;
}
+
+
+ ///
+ /// 分布式送abp版本:abp套了一层娃。但是纯粹鸡肋,不建议使用这个
+ ///
+ public IAbpDistributedLock AbpDistributedLock { get; set; }
+
+ ///
+ /// 分布式锁推荐使用版本:yyds,分布式锁永远的神!
+ ///
+ public IDistributedLockProvider DistributedLock { get; set; }
+
+ ///
+ /// 分布式锁
+ ///
+ /// 强烈吐槽一下abp,正如他们所说,abp的分布式锁单纯为了自己用,一切还是以DistributedLock为主>
+ ///
+ public async Task GetDistributedLockAsync()
+ {
+ var number = 0;
+ await Parallel.ForAsync(0, 100, async (i, cancellationToken) =>
+ {
+ await using (await DistributedLock.AcquireLockAsync("MyLockName"))
+ {
+ //执行1秒
+ number += 1;
+ }
+ });
+ var number2 = 0;
+ await Parallel.ForAsync(0, 100, async (i, cancellationToken) =>
+ {
+ //执行1秒
+ number2 += 1;
+ });
+ return $"加锁结果:{number},不加锁结果:{number2}";
+ }
}
-}
+}
\ No newline at end of file