Skip to content

Commit

Permalink
Overload UseAzureBlobLockProvider with connection string/container na…
Browse files Browse the repository at this point in the history
…me (#4648)
  • Loading branch information
LPFOXX authored Nov 24, 2023
1 parent f015e85 commit e423311
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public static DistributedLockingOptionsBuilder UseAzureBlobLockProvider(this Dis
return options;
}

public static DistributedLockingOptionsBuilder UseAzureBlobLockProvider(this DistributedLockingOptionsBuilder options, string connectionString, string blobContainerName, BlobClientOptions? blobClientOptions = null)
{
options.UseProviderFactory(sp => CreateAzureDistributedLockFactory(sp, connectionString, blobContainerName, blobClientOptions));
return options;
}

private static Func<string, IDistributedLock> CreateAzureDistributedLockFactory(IServiceProvider services, Uri blobContainerUrl)
{
var container = new BlobContainerClient(blobContainerUrl);
Expand All @@ -32,5 +38,11 @@ private static Func<string, IDistributedLock> CreateAzureDistributedLockFactory(
var container = new BlobContainerClient(blobContainerUrl, tokenCredential, blobClientOptions);
return name => new AzureBlobLeaseDistributedLock(container, name);
}

private static Func<string, IDistributedLock> CreateAzureDistributedLockFactory(IServiceProvider services, string connectionString, string blobContainerName, BlobClientOptions? blobClientOptions)
{
var container = new BlobContainerClient(connectionString, blobContainerName, blobClientOptions);
return name => new AzureBlobLeaseDistributedLock(container, name);
}
}
}
}

0 comments on commit e423311

Please sign in to comment.