Skip to content

Commit

Permalink
feat(distributed): Add Readme (#95)
Browse files Browse the repository at this point in the history
* chore: change icon and format code

* docs: Add DistributedLocking README

* chore: update Masa.Utils library package version to 0.5.0-preview.3

* chore: Add parameter default value

* chore: Medalion removes unit tests

* docs: Modify readme

* chore: Modify readme

* chore: Modify readme

* chore: Modify readme
  • Loading branch information
zhenlei520 authored Jun 24, 2022
1 parent 439a601 commit 76b1ec4
Show file tree
Hide file tree
Showing 40 changed files with 899 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<MicrosoftTeskSdkPackageVersion>16.9.4</MicrosoftTeskSdkPackageVersion>
<CoverletPackageVersion>3.0.2</CoverletPackageVersion>
<MoqPackageVersion>4.16.1</MoqPackageVersion>
<MasaUtilsPackageVersion>0.5.0-preview.2</MasaUtilsPackageVersion>
<MasaUtilsPackageVersion>0.5.0-preview.3</MasaUtilsPackageVersion>
<MapsterPackageVersion>7.3.0</MapsterPackageVersion>
<DaprPackageVersion>1.5.0</DaprPackageVersion>
<MedallionDistributedLockPackageVersion>1.0.4</MedallionDistributedLockPackageVersion>
Expand Down
25 changes: 25 additions & 0 deletions Masa.Contrib.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand Down
Binary file modified packageIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public static IConfigurationRoot CreateMasaConfiguration(
private static void ConfigureOption(
this IServiceCollection services,
IConfiguration configuration,
List<string> sectionNames, Type optionType)
List<string> sectionNames,
Type optionType)
{
IConfigurationSection? configurationSection = null;
foreach (var sectionName in sectionNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class DefaultLocalDistributedLock : IDistributedLock
{
private readonly MemoryCache<string, SemaphoreSlim> _localObjects = new();

public IDisposable? TryGet(string key, TimeSpan timeout)
public IDisposable? TryGet(string key, TimeSpan timeout = default)
{
var semaphore = GetSemaphoreSlim(key);

Expand All @@ -19,7 +19,7 @@ public class DefaultLocalDistributedLock : IDistributedLock
return new DisposeAction(semaphore);
}

public async Task<IAsyncDisposable?> TryGetAsync(string key, TimeSpan timeout, CancellationToken cancellationToken = default)
public async Task<IAsyncDisposable?> TryGetAsync(string key, TimeSpan timeout = default, CancellationToken cancellationToken = default)
{
var semaphore = GetSemaphoreSlim(key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Masa.Utils.Caching.Memory" Version="$(MasaUtilsPackageVersion)"/>
<PackageReference Include="Masa.Utils.Extensions.DependencyInjection" Version="$(MasaUtilsPackageVersion)"/>
<PackageReference Include="Masa.Utils.Caching.Memory" Version="$(MasaUtilsPackageVersion)" />
<PackageReference Include="Masa.Utils.Extensions.DependencyInjection" Version="$(MasaUtilsPackageVersion)" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj"/>
<ProjectReference Include="..\..\..\BuildingBlocks\MASA.BuildingBlocks\src\Data\Masa.BuildingBlocks.Data\Masa.BuildingBlocks.Data.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
}
}
```
Original file line number Diff line number Diff line change
@@ -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
}
}
```
Original file line number Diff line number Diff line change
@@ -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
}
}
```
Original file line number Diff line number Diff line change
@@ -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
}
}
```

Original file line number Diff line number Diff line change
@@ -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
}
}
```
Original file line number Diff line number Diff line change
@@ -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
}
}
```

Original file line number Diff line number Diff line change
@@ -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
}
}
```
Original file line number Diff line number Diff line change
@@ -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
}
}
```

Original file line number Diff line number Diff line change
@@ -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
}
}
```
Loading

0 comments on commit 76b1ec4

Please sign in to comment.