diff --git a/Directory.Build.props b/Directory.Build.props
index c5eca3ecc..5ef0dade7 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -6,7 +6,7 @@
16.9.4
3.0.2
4.16.1
- 0.5.0-preview.2
+ 0.5.0-preview.3
7.3.0
1.5.0
1.0.4
diff --git a/Masa.Contrib.sln b/Masa.Contrib.sln
index 3c90068e4..05a8f51b2 100644
--- a/Masa.Contrib.sln
+++ b/Masa.Contrib.sln
@@ -284,6 +284,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Identity", "Identity", "{5F
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Masa.Contrib.Identity.IdentityModel", "src\Identity\Masa.Contrib.Identity.IdentityModel\Masa.Contrib.Identity.IdentityModel.csproj", "{AA7876FF-3EF9-40EC-B5FF-66AB748DB93E}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DistributedLocking", "DistributedLocking", "{DB2B4DA3-EEF2-49AA-93A4-B00C25210A68}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Data.DistributedLocking.Local.Tests", "test\Masa.Contrib.Data.DistributedLocking.Local.Tests\Masa.Contrib.Data.DistributedLocking.Local.Tests.csproj", "{D91C3145-C31C-4301-A493-96F94C903CF2}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Masa.Contrib.Data.DistributedLocking.Medallion.Tests", "test\Masa.Contrib.Data.DistributedLocking.Medallion.Tests\Masa.Contrib.Data.DistributedLocking.Medallion.Tests.csproj", "{FD35BEFA-512C-4483-B5C0-ADCA35680315}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1172,6 +1178,22 @@ Global
{AA7876FF-3EF9-40EC-B5FF-66AB748DB93E}.Release|Any CPU.Build.0 = Release|Any CPU
{AA7876FF-3EF9-40EC-B5FF-66AB748DB93E}.Release|x64.ActiveCfg = Release|Any CPU
{AA7876FF-3EF9-40EC-B5FF-66AB748DB93E}.Release|x64.Build.0 = Release|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Debug|x64.Build.0 = Debug|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Release|x64.ActiveCfg = Release|Any CPU
+ {D91C3145-C31C-4301-A493-96F94C903CF2}.Release|x64.Build.0 = Release|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Debug|x64.ActiveCfg = Debug|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Debug|x64.Build.0 = Debug|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Release|x64.ActiveCfg = Release|Any CPU
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -1313,6 +1335,9 @@ Global
{8C5D0C99-59D7-4E79-9AE4-AF7AA7F2DB3D} = {07BD7788-9DC0-4BD0-9861-0C9AC13B4EB8}
{5F25960E-646D-4EA6-A648-3CAD284B6E38} = {42DF7AAC-362C-48F4-B76A-BDEEEFF17CC9}
{AA7876FF-3EF9-40EC-B5FF-66AB748DB93E} = {5F25960E-646D-4EA6-A648-3CAD284B6E38}
+ {DB2B4DA3-EEF2-49AA-93A4-B00C25210A68} = {38E6C400-90C0-493E-9266-C1602E229F1B}
+ {D91C3145-C31C-4301-A493-96F94C903CF2} = {DB2B4DA3-EEF2-49AA-93A4-B00C25210A68}
+ {FD35BEFA-512C-4483-B5C0-ADCA35680315} = {DB2B4DA3-EEF2-49AA-93A4-B00C25210A68}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {40383055-CC50-4600-AD9A-53C14F620D03}
diff --git a/packageIcon.png b/packageIcon.png
index 2128805c1..843b1105f 100644
Binary files a/packageIcon.png and b/packageIcon.png differ
diff --git a/src/BuildingBlocks/MASA.BuildingBlocks b/src/BuildingBlocks/MASA.BuildingBlocks
index bc03f3a0d..415ed143e 160000
--- a/src/BuildingBlocks/MASA.BuildingBlocks
+++ b/src/BuildingBlocks/MASA.BuildingBlocks
@@ -1 +1 @@
-Subproject commit bc03f3a0d891e035738265549a1596e284a3235d
+Subproject commit 415ed143e5bf0db31b11da720ae0902f0d61e7e2
diff --git a/src/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs b/src/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs
index fb2da5b9f..0792bcab6 100644
--- a/src/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs
+++ b/src/Configuration/Masa.Contrib.Configuration/ServiceCollectionExtensions.cs
@@ -131,7 +131,8 @@ public static IConfigurationRoot CreateMasaConfiguration(
private static void ConfigureOption(
this IServiceCollection services,
IConfiguration configuration,
- List sectionNames, Type optionType)
+ List sectionNames,
+ Type optionType)
{
IConfigurationSection? configurationSection = null;
foreach (var sectionName in sectionNames)
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/DefaultLocalDistributedLock.cs b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/DefaultLocalDistributedLock.cs
index cb72d7b43..20207331e 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/DefaultLocalDistributedLock.cs
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/DefaultLocalDistributedLock.cs
@@ -7,7 +7,7 @@ public class DefaultLocalDistributedLock : IDistributedLock
{
private readonly MemoryCache _localObjects = new();
- public IDisposable? TryGet(string key, TimeSpan timeout)
+ public IDisposable? TryGet(string key, TimeSpan timeout = default)
{
var semaphore = GetSemaphoreSlim(key);
@@ -19,7 +19,7 @@ public class DefaultLocalDistributedLock : IDistributedLock
return new DisposeAction(semaphore);
}
- public async Task TryGetAsync(string key, TimeSpan timeout, CancellationToken cancellationToken = default)
+ public async Task TryGetAsync(string key, TimeSpan timeout = default, CancellationToken cancellationToken = default)
{
var semaphore = GetSemaphoreSlim(key);
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/Masa.Contrib.Data.DistributedLocking.Local.csproj b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/Masa.Contrib.Data.DistributedLocking.Local.csproj
index f6594f796..7a9d3a22d 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/Masa.Contrib.Data.DistributedLocking.Local.csproj
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/Masa.Contrib.Data.DistributedLocking.Local.csproj
@@ -7,12 +7,12 @@
-
-
+
+
-
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.md
new file mode 100644
index 000000000..e1cca399a
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.md
@@ -0,0 +1,28 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Local
+
+## Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Local
+```
+
+1. Modify the class `Program`
+
+``` C#
+builder.Services.AddLocalDistributedLock();
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.zh-CN.md
new file mode 100644
index 000000000..c0137ea22
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Local/README.zh-CN.md
@@ -0,0 +1,28 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Local
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Local
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddLocalDistributedLock();
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.md
new file mode 100644
index 000000000..78e906f33
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Azure
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Azure
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseAzure("Replace Your connectionString", "Replace your blobContainerName");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.zh-CN.md
new file mode 100644
index 000000000..eb78e940c
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Azure
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Azure
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseAzure("Replace Your connectionString", "Replace your blobContainerName");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md
new file mode 100644
index 000000000..0696c561d
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseFileSystem("Replace your directory path");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md
new file mode 100644
index 000000000..68c4f2363
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseFileSystem("Replace your directory path");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.md
new file mode 100644
index 000000000..42008ba92
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.MySql
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.MySql
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseMySQL("Server=localhost;Database=identity;Uid=myUsername;Pwd=P@ssw0rd");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.zh-CN.md
new file mode 100644
index 000000000..42699c1fa
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.MySql/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.MySql
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.MySql
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseMySQL("Server=localhost;Database=identity;Uid=myUsername;Pwd=P@ssw0rd");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.md
new file mode 100644
index 000000000..7dfaab55e
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Oracle
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Oracle
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseOracle("Data Source=MyOracleDB;Integrated Security=yes;");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.zh-CN.md
new file mode 100644
index 000000000..891854f7c
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Oracle/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Oracle
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Oracle
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseOracle("Data Source=MyOracleDB;Integrated Security=yes;");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.md
new file mode 100644
index 000000000..e510e0d5c
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseNpgsql("Host=myserver;Username=sa;Password=P@ssw0rd;Database=identity");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.zh-CN.md
new file mode 100644
index 000000000..acd7a1b14
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.PostgreSql
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseNpgsql("Host=myserver;Username=sa;Password=P@ssw0rd;Database=identity");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/MedallionBuilderExtensions.cs b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/MedallionBuilderExtensions.cs
index a77bc5eb2..9f2e1aba5 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/MedallionBuilderExtensions.cs
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/MedallionBuilderExtensions.cs
@@ -5,7 +5,7 @@ namespace Microsoft.Extensions.DependencyInjection;
public static class MedallionBuilderExtensions
{
- public static void UseRedis(MedallionBuilder medallionBuilder,
+ public static void UseRedis(this MedallionBuilder medallionBuilder,
string connectionString,
Action? options = null)
{
@@ -17,7 +17,7 @@ public static void UseRedis(MedallionBuilder medallionBuilder,
});
}
- public static void UseRedis(MedallionBuilder medallionBuilder,
+ public static void UseRedis(this MedallionBuilder medallionBuilder,
IDatabase database,
Action? options = null)
{
@@ -25,7 +25,7 @@ public static void UseRedis(MedallionBuilder medallionBuilder,
=> new RedisDistributedSynchronizationProvider(database, options));
}
- public static void UseRedis(MedallionBuilder medallionBuilder,
+ public static void UseRedis(this MedallionBuilder medallionBuilder,
IEnumerable databases,
Action? options = null)
{
@@ -33,7 +33,7 @@ public static void UseRedis(MedallionBuilder medallionBuilder,
=> new RedisDistributedSynchronizationProvider(databases, options));
}
- public static void UseRedis(MedallionBuilder medallionBuilder,
+ public static void UseRedis(this MedallionBuilder medallionBuilder,
Action? options = null)
{
medallionBuilder.Services.AddSingleton(serviceProvider
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.md
new file mode 100644
index 000000000..6eb24eec2
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Redis
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Redis
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseRedis("127.0.0.1:6379");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.zh-CN.md
new file mode 100644
index 000000000..97abd63c1
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.Redis/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.Redis
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Redis
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseRedis("127.0.0.1:6379");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/MedallionBuilderExtensions.cs b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/MedallionBuilderExtensions.cs
index c50b77482..934b6dd45 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/MedallionBuilderExtensions.cs
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/MedallionBuilderExtensions.cs
@@ -23,13 +23,12 @@ public static void UseSqlServer(this MedallionBuilder medallionB
if (unitOfWorkManager == null)
throw new NotSupportedException("UoW is not supported");
- using (var unitOfWork = unitOfWorkManager.CreateDbContext())
- {
- var name = ConnectionStringNameAttribute.GetConnStringName(typeof(TDbContextType));
- var connectionStringProvider = unitOfWork.ServiceProvider.GetRequiredService();
- var connectionString = connectionStringProvider.GetConnectionString(name);
- return new SqlDistributedSynchronizationProvider(connectionString, options);
- }
+ using var unitOfWork = unitOfWorkManager.CreateDbContext();
+ var name = ConnectionStringNameAttribute.GetConnStringName(typeof(TDbContextType));
+ var connectionStringProvider = unitOfWork.ServiceProvider.GetRequiredService();
+ var connectionString = connectionStringProvider.GetConnectionString(name);
+ return new SqlDistributedSynchronizationProvider(connectionString, options);
+
});
}
}
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.md
new file mode 100644
index 000000000..74d937411
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=identity");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.zh-CN.md
new file mode 100644
index 000000000..399e45006
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseSqlServer("server=localhost;uid=sa;pwd=P@ssw0rd;database=identity");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/MedallionBuilderExtensions.cs b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/MedallionBuilderExtensions.cs
index 6a3c04b7b..42a36ad86 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/MedallionBuilderExtensions.cs
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/MedallionBuilderExtensions.cs
@@ -5,6 +5,11 @@ namespace Microsoft.Extensions.DependencyInjection;
public static class MedallionBuilderExtensions
{
+ ///
+ /// used to coordinate between processes on the same machine
+ ///
+ ///
+ /// specifies how frequently the implementation will check to see if the original holder of a lock/semaphore abandoned it without properly releasing it while waiting for it to become available. Defaults to 2s
public static void UseWaitHandles(this MedallionBuilder medallionBuilder,
TimeSpan? abandonmentCheckCadence = null)
{
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.md
new file mode 100644
index 000000000..1fb3a29fe
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.md
@@ -0,0 +1,33 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseWaitHandles();
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
+> Does not support cross-machine, only supports coordination between processes on the same machine
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.zh-CN.md
new file mode 100644
index 000000000..e6320c10e
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles/README.zh-CN.md
@@ -0,0 +1,33 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.WaitHandles
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseWaitHandles();
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
+> 不支持跨机器,仅支持同一台机器上进程之间进行协调
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper.csproj b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper.csproj
index cd04d9308..dc9ce2fa4 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper.csproj
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper.csproj
@@ -7,11 +7,11 @@
-
+
-
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.md
new file mode 100644
index 000000000..6174e8e2f
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.md
@@ -0,0 +1,31 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseZooKeeper("Replace your ZooKeeper connectionString");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.zh-CN.md
new file mode 100644
index 000000000..2ea451b18
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.zh-CN.md
@@ -0,0 +1,32 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseZooKeeper("Replace your ZooKeeper connectionString");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/DefaultMedallionDistributedLock.cs b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/DefaultMedallionDistributedLock.cs
index 5fd6484bc..433567070 100644
--- a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/DefaultMedallionDistributedLock.cs
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/DefaultMedallionDistributedLock.cs
@@ -10,25 +10,22 @@ public class DefaultMedallionDistributedLock : IMasaDistributedLock
public DefaultMedallionDistributedLock(IDistributedLockProvider distributedLockProvider)
=> _distributedLockProvider = distributedLockProvider;
- public IDisposable? TryGet(string key, TimeSpan timeout)
+ public IDisposable? TryGet(string key, TimeSpan timeout = default)
{
ArgumentNullOrWhiteSpaceException.ThrowIfNullOrWhiteSpace(key);
var handle = _distributedLockProvider.TryAcquireLock(key, timeout);
if (handle == null)
- {
return null;
- }
+
return new DisposeAction(handle);
}
- public async Task TryGetAsync(string key, TimeSpan timeout, CancellationToken cancellationToken = default)
+ public async Task TryGetAsync(string key, TimeSpan timeout = default, CancellationToken cancellationToken = default)
{
ArgumentNullOrWhiteSpaceException.ThrowIfNullOrWhiteSpace(key);
var handle = await _distributedLockProvider.TryAcquireLockAsync(key, timeout, cancellationToken);
if (handle == null)
- {
return null;
- }
return new DisposeAction(handle);
}
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.md
new file mode 100644
index 000000000..acf77b11e
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.md
@@ -0,0 +1,46 @@
+[中](README.zh-CN.md) | EN
+
+## Masa.Contrib.Data.DistributedLocking.Medallion
+
+Masa.Contrib.Data.DistributedLocking.Medallion is a distributed lock based on [DistributedLock](https://github.com/madelson/DistributedLock)
+
+### Implementations
+
+- [Azure](../Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.md)
+- [FileSystem](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [MySql](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [Oracle](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [PostgreSql](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [Redis](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [SqlServer](../Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.md)
+- [WaitHandles](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.md)
+- [ZooKeeper](../Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.md)
+
+### Example:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Redis// an example of Redis
+```
+
+1. Modify `Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseRedis("127.0.0.1:6379");
+});
+```
+
+2. Use distributed locks
+
+``` C#
+IDistributedLock distributedLock;//Get `IDistributedLock` from DI
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
\ No newline at end of file
diff --git a/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.zh-CN.md b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.zh-CN.md
new file mode 100644
index 000000000..3bd2fd25d
--- /dev/null
+++ b/src/Data/DistributedLocking/Masa.Contrib.Data.DistributedLocking.Medallion/README.zh-CN.md
@@ -0,0 +1,47 @@
+中 | [EN](README.md)
+
+## Masa.Contrib.Data.DistributedLocking.Medallion
+
+Masa.Contrib.Data.DistributedLocking.Medallion是基于[DistributedLock](https://github.com/madelson/DistributedLock)的一个分布式锁
+
+## 实现
+
+- [Azure](../Masa.Contrib.Data.DistributedLocking.Medallion.Azure/README.zh-CN.md)
+- [FileSystem](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [MySql](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [Oracle](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [PostgreSql](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [Redis](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [SqlServer](../Masa.Contrib.Data.DistributedLocking.Medallion.SqlServer/README.zh-CN.md)
+- [WaitHandles](../Masa.Contrib.Data.DistributedLocking.Medallion.FileSystem/README.zh-CN.md)
+- [ZooKeeper](../Masa.Contrib.Data.DistributedLocking.Medallion.ZooKeeper/README.zh-CN.md)
+
+## 用例:
+
+```c#
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion
+Install-Package Masa.Contrib.Data.DistributedLocking.Medallion.Redis//以Redis举例
+```
+
+1. 修改类`Program`
+
+``` C#
+builder.Services.AddDistributedLock(medallionBuilder =>
+{
+ medallionBuilder.UseRedis("127.0.0.1:6379");
+});
+```
+
+2. 使用分布式锁
+
+``` C#
+IDistributedLock distributedLock;//从DI获取`IDistributedLock`
+using (var lockObj = distributedLock.TryGet("Replace Your Lock Name"))
+{
+ if (lockObj != null)
+ {
+ // todo: The code that needs to be executed after acquiring the distributed lock
+ }
+}
+```
+
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/LocalDistributedLockTest.cs b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/LocalDistributedLockTest.cs
new file mode 100644
index 000000000..431d4ebcb
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/LocalDistributedLockTest.cs
@@ -0,0 +1,32 @@
+// Copyright (c) MASA Stack All rights reserved.
+// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+
+namespace Masa.Contrib.Data.DistributedLocking.Local.Tests;
+
+[TestClass]
+public class LocalDistributedLockTest
+{
+ private IDistributedLock DistributedLock { get; set; }
+
+ [TestInitialize]
+ public void Initialize()
+ {
+ var services = new ServiceCollection();
+ services.AddLocalDistributedLock();
+ DistributedLock = services.GetInstance();
+ }
+
+ [TestMethod]
+ public void TestDistributedLock()
+ {
+ using var obj = DistributedLock.TryGet("test", TimeSpan.FromSeconds(1));
+ Assert.IsNotNull(obj);
+ }
+
+ [TestMethod]
+ public async Task TestDistributedLockAsync()
+ {
+ await using var obj = await DistributedLock.TryGetAsync("test", TimeSpan.FromSeconds(1));
+ Assert.IsNotNull(obj);
+ }
+}
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/Masa.Contrib.Data.DistributedLocking.Local.Tests.csproj b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/Masa.Contrib.Data.DistributedLocking.Local.Tests.csproj
new file mode 100644
index 000000000..518715fb7
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/Masa.Contrib.Data.DistributedLocking.Local.Tests.csproj
@@ -0,0 +1,21 @@
+
+
+
+ net6.0
+ enable
+ enable
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/_Imports.cs b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/_Imports.cs
new file mode 100644
index 000000000..7c77986d2
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Local.Tests/_Imports.cs
@@ -0,0 +1,6 @@
+// Copyright (c) MASA Stack All rights reserved.
+// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+
+global using Masa.BuildingBlocks.Data;
+global using Microsoft.Extensions.DependencyInjection;
+global using Microsoft.VisualStudio.TestTools.UnitTesting;
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/DefaultMedallionDistributedLockTest.cs b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/DefaultMedallionDistributedLockTest.cs
new file mode 100644
index 000000000..e0bedd1bf
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/DefaultMedallionDistributedLockTest.cs
@@ -0,0 +1,38 @@
+// Copyright (c) MASA Stack All rights reserved.
+// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+
+namespace Masa.Contrib.Data.DistributedLocking.Medallion.Tests;
+
+///
+/// Only supports local testing
+///
+[TestClass]
+public class DefaultMedallionDistributedLockTest
+{
+ // private IDistributedLock DistributedLock { get; set; }
+ //
+ // [TestInitialize]
+ // public void Initialize()
+ // {
+ // var services = new ServiceCollection();
+ // services.AddDistributedLock(medallionBuilder =>
+ // {
+ // medallionBuilder.UseRedis("127.0.0.1:6379");
+ // });
+ // DistributedLock = services.GetInstance();
+ // }
+ //
+ // [TestMethod]
+ // public void TestDistributedLock()
+ // {
+ // using var obj = DistributedLock.TryGet("test", TimeSpan.FromSeconds(1));
+ // Assert.IsNotNull(obj);
+ // }
+ //
+ // [TestMethod]
+ // public async Task TestDistributedLockAsync()
+ // {
+ // await using var obj = await DistributedLock.TryGetAsync("test", TimeSpan.FromSeconds(1));
+ // Assert.IsNotNull(obj);
+ // }
+}
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/Masa.Contrib.Data.DistributedLocking.Medallion.Tests.csproj b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/Masa.Contrib.Data.DistributedLocking.Medallion.Tests.csproj
new file mode 100644
index 000000000..f02678d00
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/Masa.Contrib.Data.DistributedLocking.Medallion.Tests.csproj
@@ -0,0 +1,23 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/_Imports.cs b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/_Imports.cs
new file mode 100644
index 000000000..7c77986d2
--- /dev/null
+++ b/test/Masa.Contrib.Data.DistributedLocking.Medallion.Tests/_Imports.cs
@@ -0,0 +1,6 @@
+// Copyright (c) MASA Stack All rights reserved.
+// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+
+global using Masa.BuildingBlocks.Data;
+global using Microsoft.Extensions.DependencyInjection;
+global using Microsoft.VisualStudio.TestTools.UnitTesting;