Skip to content

Commit 44f6e62

Browse files
authored
Added sample (#2)
1 parent 38b30f6 commit 44f6e62

File tree

4 files changed

+57
-4
lines changed

4 files changed

+57
-4
lines changed

Locks.sln

+9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{8AB8A443
1111
EndProject
1212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Locks.Tests", "tests\Locks.Tests\Locks.Tests.csproj", "{4942FB20-6E79-4AA6-B607-728F67291811}"
1313
EndProject
14+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{1E0E5F59-5328-457A-B420-5E104EDFA528}"
15+
EndProject
16+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.MemoryLock", "samples\Samples.MemoryLock\Samples.MemoryLock.csproj", "{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC}"
17+
EndProject
1418
Global
1519
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1620
Debug|Any CPU = Debug|Any CPU
@@ -25,13 +29,18 @@ Global
2529
{4942FB20-6E79-4AA6-B607-728F67291811}.Debug|Any CPU.Build.0 = Debug|Any CPU
2630
{4942FB20-6E79-4AA6-B607-728F67291811}.Release|Any CPU.ActiveCfg = Release|Any CPU
2731
{4942FB20-6E79-4AA6-B607-728F67291811}.Release|Any CPU.Build.0 = Release|Any CPU
32+
{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33+
{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
34+
{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
35+
{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC}.Release|Any CPU.Build.0 = Release|Any CPU
2836
EndGlobalSection
2937
GlobalSection(SolutionProperties) = preSolution
3038
HideSolutionNode = FALSE
3139
EndGlobalSection
3240
GlobalSection(NestedProjects) = preSolution
3341
{6F5A38A8-D6E1-4D1D-99B4-85CE7C40F468} = {1E772EE5-484B-4803-9FA1-6681DC601553}
3442
{4942FB20-6E79-4AA6-B607-728F67291811} = {8AB8A443-B3CA-49F8-9BD6-6476AA7F9EEC}
43+
{C2BAB68A-9C7C-41E4-BE9F-A1C457AEE1AC} = {1E0E5F59-5328-457A-B420-5E104EDFA528}
3544
EndGlobalSection
3645
GlobalSection(ExtensibilityGlobals) = postSolution
3746
SolutionGuid = {3E2C15DA-E3F4-407A-9BD5-A87A4D07597C}

README.md

+10-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
<h3 align="center">Synchronization mechanisms in .NET 🔐</h3>
66

7+
<h4 align="center"><i>Prevent race contidion</i></h3>
8+
79
<p align="center">
810
<a href="https://www.nuget.org/packages/Locks"><strong>Package</strong></a>
911

@@ -16,11 +18,15 @@
1618

1719
</div>
1820

19-
### 🔥 Examples of problems in multi-threaded and distributed environments
20-
- **Race contidion**
21-
- **Overconsumption of resources**
2221

23-
In progress...
22+
### Usage
23+
24+
```C#
25+
using (memoryLock.Acquire("YOUR_KEY"))
26+
{
27+
// Shared resource
28+
}
29+
```
2430

2531
## :balance_scale: License
2632
This project is under the [MIT License](https://github.com/adimiko/Locks/blob/main/LICENSE).

samples/Samples.MemoryLock/Program.cs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Locks;
2+
using Microsoft.Extensions.DependencyInjection;
3+
4+
5+
IServiceCollection services = new ServiceCollection();
6+
7+
services.AddMemoryLock();
8+
9+
var sp = services.BuildServiceProvider();
10+
11+
using (var scope = sp.CreateScope())
12+
{
13+
var memoryLock = scope.ServiceProvider.GetRequiredService<IMemoryLock>();
14+
15+
using (memoryLock.Acquire("YOUR_KEY"))
16+
{
17+
Console.WriteLine("YOUR_LOGIC");
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\source\Locks\Locks.csproj" />
17+
</ItemGroup>
18+
19+
</Project>

0 commit comments

Comments
 (0)