EasilyNET.MongoDistributedLock.AspNetCore
2.1.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package EasilyNET.MongoDistributedLock.AspNetCore --version 2.1.7
NuGet\Install-Package EasilyNET.MongoDistributedLock.AspNetCore -Version 2.1.7
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasilyNET.MongoDistributedLock.AspNetCore" Version="2.1.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasilyNET.MongoDistributedLock.AspNetCore --version 2.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EasilyNET.MongoDistributedLock.AspNetCore, 2.1.7"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasilyNET.MongoDistributedLock.AspNetCore as a Cake Addin #addin nuget:?package=EasilyNET.MongoDistributedLock.AspNetCore&version=2.1.7 // Install EasilyNET.MongoDistributedLock.AspNetCore as a Cake Tool #tool nuget:?package=EasilyNET.MongoDistributedLock.AspNetCore&version=2.1.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
EasilyNET.MongoDistributedLock.AspNetCore
EasilyNET.MongoDistributedLock.AspNetCore 让基于 EasilyNET.MongoDistributedLock 的使用更简单.
注册分布式锁服务,用来配置一些基本信息
// 使用默认配置
builder.Services.AddMongoDistributedLock();
// 自定义一些配置
builder.Services.AddMongoDistributedLock(op =>
{
op.DatabaseName = "test_locks";
op.MaxDocument = 100;
...
});
- 使用 IMongoLockFactory 来注入工厂服务
public class DistributedLockTest(IMongoLockFactory lockFactory)
{
public async Task<dynamic> AcquireLock()
{
// 这里使用一个随机的ID作为锁ID,相当于其他锁中的Key.用来区分不同的业务的锁,也可以将不同的业务类型放到MongoDB中存起来,然后再使用的时候再取获取这个id
const string lockId = "64d44afde4473b85a177084c";
var mongoLock = lockFactory.GenerateNewLock(ObjectId.Parse(lockId));
var acq = await mongoLock.AcquireAsync(TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(0));
try
{
if (acq.Acquired)
{
// 关键部分,它不能一次由任何服务器上的多个线程执行
// ...
// ...
}
else
{
// 超时!也许另一个线程没有释放锁...我们可以再试一次或抛出例外
}
}
finally
{
// 如果(acq.Acquired)无需手动操作
await mongoLock.ReleaseAsync(acq);
}
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- EasilyNET.MongoDistributedLock (>= 2.1.7)
-
net9.0
- EasilyNET.MongoDistributedLock (>= 2.1.7)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
3.24.1113.100 | 92 | 11/13/2024 |
3.24.1112.125 | 83 | 11/12/2024 |
3.24.1107.140 | 81 | 11/7/2024 |
3.24.1107.54 | 77 | 11/7/2024 |
3.24.1107.34 | 84 | 11/7/2024 |
3.24.1105.111 | 80 | 11/5/2024 |
3.24.1103.31 | 90 | 11/2/2024 |
3.24.1103 | 85 | 11/2/2024 |
3.24.1031.135 | 77 | 10/31/2024 |
3.24.1031.112 | 70 | 10/31/2024 |
3.24.1031.104 | 73 | 10/31/2024 |
3.24.1029.142 | 88 | 10/29/2024 |
3.24.1025.30 | 84 | 10/24/2024 |
3.24.1022.142 | 66 | 10/22/2024 |
3.24.1018.204 | 133 | 10/18/2024 |
3.24.1018.175 | 138 | 10/18/2024 |
3.24.1018.166 | 128 | 10/18/2024 |
3.24.1018.93 | 132 | 10/18/2024 |
3.24.1017.42 | 84 | 10/16/2024 |
3.24.1016.161 | 88 | 10/16/2024 |
3.24.1015.231 | 85 | 10/15/2024 |
3.24.1015.14 | 87 | 10/14/2024 |
3.24.1012.114 | 89 | 10/12/2024 |
3.24.1009.115 | 98 | 10/9/2024 |
3.24.1008.160 | 86 | 10/8/2024 |
3.24.1008.133 | 91 | 10/8/2024 |
3.24.1007.185 | 93 | 10/7/2024 |
3.24.1003.33 | 93 | 10/2/2024 |
3.24.1002.162 | 98 | 10/2/2024 |
3.24.929.143 | 104 | 9/29/2024 |
3.24.929.141 | 87 | 9/29/2024 |
3.24.929.131 | 84 | 9/29/2024 |
3.24.929.122 | 75 | 9/29/2024 |
3.24.926.184 | 80 | 9/26/2024 |
3.24.926.182 | 78 | 9/26/2024 |
3.24.926.175 | 93 | 9/26/2024 |
3.24.924.160 | 91 | 9/24/2024 |
3.24.924.133 | 105 | 9/24/2024 |
3.24.924.124 | 92 | 9/24/2024 |
3.24.924.10 | 88 | 9/23/2024 |
3.24.924.1 | 85 | 9/23/2024 |
3.24.923.234 | 104 | 9/23/2024 |
3.24.923.232 | 111 | 9/23/2024 |
3.24.923.155 | 88 | 9/23/2024 |
3.24.919.92 | 99 | 9/19/2024 |
3.24.914.125 | 108 | 9/14/2024 |
3.24.914.115 | 110 | 9/14/2024 |
3.24.914.111 | 106 | 9/14/2024 |
3.24.911.95 | 114 | 9/11/2024 |
3.24.908.215 | 85 | 9/8/2024 |
3.24.904.200 | 90 | 9/4/2024 |
3.24.828.163 | 116 | 8/28/2024 |
3.24.820.173 | 102 | 8/20/2024 |
3.24.814.92 | 119 | 8/14/2024 |
3.24.812.115 | 107 | 8/12/2024 |
3.24.802.100 | 79 | 8/2/2024 |
3.24.801.162 | 86 | 8/1/2024 |
3.24.801.160 | 83 | 8/1/2024 |
3.24.801.155 | 87 | 8/1/2024 |
3.24.730.164 | 83 | 7/30/2024 |
3.24.730.91 | 80 | 7/30/2024 |
3.24.724.91 | 80 | 7/24/2024 |
3.24.718.105 | 108 | 7/18/2024 |
3.24.716.95 | 103 | 7/16/2024 |
3.24.712.94 | 97 | 7/12/2024 |
3.24.710.14 | 116 | 7/9/2024 |
3.24.709.105 | 113 | 7/9/2024 |
3.24.704.94 | 113 | 7/4/2024 |
3.24.701.90 | 131 | 7/1/2024 |
3.24.628.114 | 115 | 6/28/2024 |
3.24.627.145 | 103 | 6/27/2024 |
3.24.620.160 | 100 | 6/20/2024 |
3.24.613.115 | 108 | 6/13/2024 |
3.24.612.95 | 105 | 6/12/2024 |
3.24.528.90 | 109 | 5/28/2024 |
3.24.522.84 | 124 | 5/22/2024 |
3.24.512.213 | 100 | 5/12/2024 |
3.24.508.112 | 128 | 5/8/2024 |
2.2024.428.71 | 116 | 4/28/2024 |
2.2024.427.1128 | 117 | 4/27/2024 |
2.2.72 | 123 | 4/14/2024 |
2.2.71 | 115 | 4/12/2024 |
2.2.8 | 111 | 4/26/2024 |
2.2.6 | 108 | 4/10/2024 |
2.2.5 | 129 | 3/26/2024 |
2.2.4 | 127 | 3/25/2024 |
2.2.3 | 132 | 3/24/2024 |
2.2.2 | 134 | 3/21/2024 |
2.2.1 | 137 | 3/20/2024 |
2.2.0 | 128 | 3/13/2024 |
2.1.9 | 128 | 2/21/2024 |
2.1.8 | 126 | 2/18/2024 |
2.1.7 | 119 | 2/16/2024 |
2.1.6 | 118 | 2/14/2024 |
2.1.5 | 123 | 2/14/2024 |
2.1.4 | 140 | 2/9/2024 |
2.1.3 | 165 | 2/8/2024 |
2.1.2 | 115 | 2/5/2024 |
2.1.1.2 | 190 | 12/26/2023 |
2.1.1.1 | 126 | 12/26/2023 |
2.1.1 | 141 | 12/25/2023 |
2.1.0 | 145 | 12/17/2023 |
2.0.11 | 164 | 12/6/2023 |
2.0.1 | 162 | 11/15/2023 |
2.0.0 | 142 | 11/14/2023 |
1.9.1 | 146 | 11/1/2023 |
1.9.0 | 142 | 10/19/2023 |
1.9.0-preview2 | 123 | 10/12/2023 |
1.9.0-preview1 | 115 | 10/12/2023 |
1.8.9 | 158 | 10/11/2023 |
1.8.8 | 147 | 10/11/2023 |
1.8.7-rc2 | 118 | 9/21/2023 |
1.8.7-rc1 | 122 | 9/12/2023 |
1.8.6 | 169 | 8/31/2023 |
1.8.5 | 151 | 8/25/2023 |
1.8.4 | 162 | 8/24/2023 |
1.8.3 | 168 | 8/23/2023 |
1.8.2 | 162 | 8/22/2023 |
1.8.1 | 170 | 8/18/2023 |
1.8.0 | 182 | 8/15/2023 |
1.7.9 | 190 | 8/11/2023 |
1.7.8 | 171 | 8/11/2023 |
1.7.7 | 175 | 8/10/2023 |
1.7.6 | 195 | 8/9/2023 |
1.7.5 | 162 | 8/9/2023 |
1.7.4 | 180 | 8/3/2023 |
1.7.3 | 177 | 8/1/2023 |
1.7.2 | 172 | 7/31/2023 |
1.7.1 | 168 | 7/27/2023 |
1.7.0 | 177 | 7/27/2023 |