Skip to content

Commit c42c655

Browse files
authored
Edits and Updates for readability
1 parent 10adf55 commit c42c655

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

README.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Sql Server (e.g. sp_getapplock & sp_releaseapplock). Sql Server provides a very
44
capability and this library exposes this in an easy to use C# .Net Standard API using custom extension methods
55
on the SqlConnection and SqlTransaction classes of the SqlClient libraries.
66

7+
### Nuget Package
8+
To use in your project, add the appropriate package to your project for the namespace you are using:
9+
- [SqlAppLockHelper.MicrosoftData NuGet package](https://www.nuget.org/packages/SqlAppLockHelper.MicrosoftData/)
10+
- [SqlAppLockHelper.SystemData NuGet package](https://www.nuget.org/packages/SqlAppLockHelper.SystemData/)
11+
712
### [Buy me a Coffee ☕](https://www.buymeacoffee.com/cajuncoding)
813
*I'm happy to share with the community, but if you find this useful (e.g for professional use), and are so inclinded,
914
then I do love-me-some-coffee!*
@@ -12,23 +17,24 @@ then I do love-me-some-coffee!*
1217
<img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy Me A Coffee" height="41" width="174">
1318
</a>
1419

15-
#### SqlClient Namespaces:
16-
There are two namespaces for SqlClient, and this library supports both:
20+
## Sql Server Details:
21+
#### Both SqlClient Namespaces are Supported:
22+
The library supports both SqlClient libraries:
1723
- System.Data.SqlClient (Legacy; long term supported for existing applications)
1824
- Microsoft.Data.SqlClient (Future; recommended go-forward library for new applications)
1925

2026
The usage for both is identical, with only the import being different based on the library you are using (or both in some edge cases):
2127
- `using SqlAppLockHelper.SystemDataNS;`
2228
- `using SqlAppLockHelper.MicrosoftDataNS;`
2329

24-
#### Locking Scopes (maps to the `@LockOwner` parameter of `sp_getapplock`):
30+
#### Both Transaction & Connection Locking Scopes are supported:
2531
There are two scopes for Locks that are supported:
26-
- Session Scope (will automatically be released by Sql Server when the Sql Connection is disposed/closed; or may be optionally explicitly released).
27-
- Transaction Scope (Will automatically be released by Sql Server when Sql Transaction is Commited/Rolled-back/Closed; or can be optionally explicitly released).
28-
29-
Note: Explicit release can be done anytime from the `SqlServerAppLock` class returned from an acquired lock, and is also intrinsically done via IDisposable/IAsyncDisposable on the `SqlServerAppLock` class to provide reliable release when scope closes via C# `using` pattern.
32+
- **Session Scope** (aka Connection) - will automatically be released by Sql Server when the Sql Connection is disposed/closed; or may be optionally explicitly released.
33+
- **Transaction Scope** - Will automatically be released by Sql Server when Sql Transaction is Commited/Rolled-back/Closed; or can be optionally explicitly released.
34+
35+
_NOTE: These scopes map to the underlying maps to the `@LockOwner` parameter of `sp_getapplock`_)
3036

31-
#### Usage Notes:
37+
### Usage Notes:
3238
- The generally recommended approach is to use the *Transaction* scope because it is slightly safer (e.g. more resilient against
3339
abandoned locks) by allowing the Locks to automatically expire with the Transaction; and is the default behavior of Sql Server.
3440
- However the *Session* scope is reliably implemented as long as you always close/dispose of the connection and/or via the `SqlServerAppLock` class; which also implements IDisposable/IAsyncDisposable C# interfaces.
@@ -40,20 +46,17 @@ acquire the lock.
4046
- [sp_getapplock](https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-getapplock-transact-sql?view=sql-server-ver15)
4147
- [sp_releaseapplock](https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-releaseapplock-transact-sql?view=sql-server-ver15)
4248

43-
#### Use Cases:
49+
### Releasing Locks with IDisposable/IAsyncDisposable Patterns:
50+
Explicit release can be done anytime from the `SqlServerAppLock` class returned from an acquired lock, and is also intrinsically done via IDisposable/IAsyncDisposable on the `SqlServerAppLock` class to provide reliable release when scope closes via C# `using` pattern.
51+
52+
### Use Cases:
4453
- Provide a lock implementation similar to C# `lock (...) {}` but on a distributed scale across many instances of an
4554
application (e.g. Azure Functions, Load Balanced Servers, etc.).
4655
- Provide a mutex lock to ensure code is only ever run by one instance at a time (e.g. Bulk Loading or Bulk Synchronization processing,
4756
Queue Processing logic, Transactional Outbox Pattern, etc.).
4857
- I'm sure there are many more... but these are the best examples that I've needed to implement in enterprises.
4958

50-
51-
## Nuget Package
52-
To use in your project, add the appropriate package to your project for the namespace you are using:
53-
- [SqlAppLockHelper.MicrosoftData NuGet package](https://www.nuget.org/packages/SqlAppLockHelper.MicrosoftData/)
54-
- [SqlAppLockHelper.SystemData NuGet package](https://www.nuget.org/packages/SqlAppLockHelper.SystemData/)
55-
56-
## Usage:
59+
## Code Samples/Snippets:
5760

5861
#### Import the Custom Extensions:
5962
First import the extensions for the library you are using:

0 commit comments

Comments
 (0)