Fasjeit / DbLocks

Simple DbLocks for EF sync

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

DbLocks

DbLocks is a C# library sample that provides an easy way to create postgress db based sync locks on objects.

Usage

// Create db table for the lock entity
public class ObjectLockEntity : IBaseEntity
{
    public string? Id { get; set; }

    public string? Type { get; set; }
}

// Create typed lock provider
public class ClientLockProvider : LockProvider
{
    public HubClientLockProvider(IObjectLockStore lockStore)
        : base(lockStore, "Client")
    {
    }
}

var clientLockProvider = new HubClientLockProvider(store);

// Use it to acquire lock client objects
// If object already locked by other lock - wait untill lock will be released.
 await using (var clientLock = await clientLockProvider.GetAndAcquireAsync(client.Id, this.cnsSource.Token))
{
    // use client
}// lock will release as Dispose

About

Simple DbLocks for EF sync

License:MIT License


Languages

Language:C# 100.0%