diff --git a/docs/en/solution-templates/single-layer-web-application/background-workers.md b/docs/en/solution-templates/single-layer-web-application/background-workers.md index 7075d85879..4153d7b9b5 100644 --- a/docs/en/solution-templates/single-layer-web-application/background-workers.md +++ b/docs/en/solution-templates/single-layer-web-application/background-workers.md @@ -8,8 +8,8 @@ "Path": "solution-templates/single-layer-web-application/background-jobs" }, "Next": { - "Name": "Multi-Tenancy", - "Path": "solution-templates/single-layer-web-application/multi-tenancy" + "Name": "Distributed Locking", + "Path": "solution-templates/single-layer-web-application/distributed-locking" } } ``` diff --git a/docs/en/solution-templates/single-layer-web-application/distributed-locking.md b/docs/en/solution-templates/single-layer-web-application/distributed-locking.md new file mode 100644 index 0000000000..09f032fe16 --- /dev/null +++ b/docs/en/solution-templates/single-layer-web-application/distributed-locking.md @@ -0,0 +1,44 @@ +# Single Layer Solution: Distributed Locking + +```json +//[doc-nav] +{ + "Previous": { + "Name": "Background Workers", + "Path": "solution-templates/single-layer-web-application/background-workers" + }, + "Next": { + "Name": "Multi-Tenancy", + "Path": "solution-templates/single-layer-web-application/multi-tenancy" + } +} +``` + +Distributed locking is a mechanism that allows multiple instances of an application to coordinate and synchronize access to shared resources. It is useful for scenarios where multiple instances of an application need to ensure that only one instance can access a resource at a time. You can learn more in the [Distributed Locking](../../framework/infrastructure/distributed-locking.md) document. + +## Distributed Locking in Single Layer Solutions + +The single-layer solution templates does not include distributed lock package by default. You can add the [Volo.Abp.DistributedLock](https://www.nuget.org/packages/Volo.Abp.DistributedLocking) package to your project to use distributed locking. This package provides a distributed lock mechanism that works with Redis. You can inject the `IAbpDistributedLock` service to acquire and release. Here is an example of using distributed locking in your application: + +```csharp +public class MyService : ITransientDependency +{ + private readonly IAbpDistributedLock _distributedLock; + + public MyService(IAbpDistributedLock distributedLock) + { + _distributedLock = distributedLock; + } + + public async Task MyMethodAsync() + { + await using (var handle = await _distributedLock.TryAcquireAsync("MyLockName")) + { + if (handle != null) + { + // your code that access the shared resource + } + } + } +} +``` diff --git a/docs/en/solution-templates/single-layer-web-application/index.md b/docs/en/solution-templates/single-layer-web-application/index.md index be7908d87b..cccba5f1ea 100644 --- a/docs/en/solution-templates/single-layer-web-application/index.md +++ b/docs/en/solution-templates/single-layer-web-application/index.md @@ -30,6 +30,7 @@ ABP Studio offers pre-architected, production-ready templates to quickly start a * [Swagger integration](swagger-integration.md) * [Bacground Jobs](background-jobs.md) * [Background Workers](background-workers.md) + * [Distributed Locking](distributed-locking.md) * [Multi-Tenancy](multi-tenancy.md) * [BLOB storing](blob-storing.md) * [CORS configuration](cors-configuration.md) \ No newline at end of file diff --git a/docs/en/solution-templates/single-layer-web-application/multi-tenancy.md b/docs/en/solution-templates/single-layer-web-application/multi-tenancy.md index 8a9a9be41f..b2cd042d0e 100644 --- a/docs/en/solution-templates/single-layer-web-application/multi-tenancy.md +++ b/docs/en/solution-templates/single-layer-web-application/multi-tenancy.md @@ -4,8 +4,8 @@ //[doc-nav] { "Previous": { - "Name": "Background Workers", - "Path": "solution-templates/single-layer-web-application/background-workers" + "Name": "Distributed Locking", + "Path": "solution-templates/single-layer-web-application/distributed-locking" }, "Next": { "Name": "BLOB storing",