mirror of https://github.com/abpframework/abp.git
11 changed files with 146 additions and 1 deletions
@ -0,0 +1,3 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<ConfigureAwait /> |
|||
</Weavers> |
|||
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> |
|||
<!-- This file was generated by Fody. Manual changes to this file will be lost when your project is rebuilt. --> |
|||
<xs:element name="Weavers"> |
|||
<xs:complexType> |
|||
<xs:all> |
|||
<xs:element name="ConfigureAwait" minOccurs="0" maxOccurs="1"> |
|||
<xs:complexType> |
|||
<xs:attribute name="ContinueOnCapturedContext" type="xs:boolean" /> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:all> |
|||
<xs:attribute name="VerifyAssembly" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'true' to run assembly verification (PEVerify) on the target assembly after all weavers have been executed.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="VerifyIgnoreCodes" type="xs:string"> |
|||
<xs:annotation> |
|||
<xs:documentation>A comma-separated list of error codes that can be safely ignored in assembly verification.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
<xs:attribute name="GenerateXsd" type="xs:boolean"> |
|||
<xs:annotation> |
|||
<xs:documentation>'false' to turn off automatic generation of the XML Schema file.</xs:documentation> |
|||
</xs:annotation> |
|||
</xs:attribute> |
|||
</xs:complexType> |
|||
</xs:element> |
|||
</xs:schema> |
|||
@ -0,0 +1,18 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\..\configureawait.props" /> |
|||
<Import Project="..\..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<ImplicitUsings>enable</ImplicitUsings> |
|||
<Nullable>enable</Nullable> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Volo.Abp.Dapr\Volo.Abp.Dapr.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.DistributedLocking.Dapr; |
|||
|
|||
public class AbpDistributedLockDaprOptions |
|||
{ |
|||
public string StoreName { get; set; } |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.Dapr; |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.DistributedLocking.Dapr; |
|||
|
|||
[DependsOn( |
|||
typeof(AbpDistributedLockingAbstractionsModule), |
|||
typeof(AbpDaprModule))] |
|||
public class AbpDistributedLockingDaprModule : AbpModule |
|||
{ |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.Dapr; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.DistributedLocking.Dapr; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class DaprAbpDistributedLock : IAbpDistributedLock, ITransientDependency |
|||
{ |
|||
protected AbpDaprClientFactory DaprClientFactory { get; } |
|||
protected AbpDistributedLockDaprOptions DistributedLockDaprOptions { get; } |
|||
protected AbpDaprOptions DaprOptions { get; } |
|||
|
|||
public DaprAbpDistributedLock( |
|||
AbpDaprClientFactory daprClientFactory, |
|||
IOptions<AbpDistributedLockDaprOptions> distributedLockDaprOptions, |
|||
IOptions<AbpDaprOptions> daprOptions) |
|||
{ |
|||
DaprClientFactory = daprClientFactory; |
|||
DaprOptions = daprOptions.Value; |
|||
DistributedLockDaprOptions = distributedLockDaprOptions.Value; |
|||
} |
|||
|
|||
public async Task<IAbpDistributedLockHandle> TryAcquireAsync( |
|||
string name, |
|||
TimeSpan timeout = default, |
|||
CancellationToken cancellationToken = default) |
|||
{ |
|||
if (timeout == default) |
|||
{ |
|||
timeout = TimeSpan.FromSeconds(30); |
|||
} |
|||
|
|||
var daprClient = await DaprClientFactory.CreateAsync(); |
|||
|
|||
var lockResponse = await daprClient.Lock( |
|||
DistributedLockDaprOptions.StoreName, |
|||
name, |
|||
DaprOptions.AppId, |
|||
timeout.Seconds, |
|||
cancellationToken); |
|||
|
|||
if (lockResponse == null || !lockResponse.Success) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return new DaprAbpDistributedLockHandle(lockResponse); |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
using Dapr.Client; |
|||
|
|||
namespace Volo.Abp.DistributedLocking.Dapr; |
|||
|
|||
public class DaprAbpDistributedLockHandle : IAbpDistributedLockHandle |
|||
{ |
|||
protected TryLockResponse LockResponse { get; } |
|||
|
|||
public DaprAbpDistributedLockHandle(TryLockResponse lockResponse) |
|||
{ |
|||
LockResponse = lockResponse; |
|||
} |
|||
|
|||
public async ValueTask DisposeAsync() |
|||
{ |
|||
await LockResponse.DisposeAsync(); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue