-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a blob container client factory for customisation
Allows blob containers to be customised based on grainType and grain id. This is wrapped in an interface to allow injection of dependencies and state to be maintained.
Showing
3 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/Azure/Orleans.Persistence.AzureStorage/Providers/Storage/IBlobContainerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Orleans.Configuration; | ||
using Orleans.Runtime; | ||
|
||
namespace Orleans.Storage; | ||
|
||
/// <summary> | ||
/// A factory for building container clients for blob storage using grainType and grainId | ||
/// </summary> | ||
public interface IBlobContainerFactory | ||
{ | ||
/// <summary> | ||
/// Build a container for the specific grain type and grain id | ||
/// </summary> | ||
/// <param name="grainType">The grain type</param> | ||
/// <param name="grainId">The grain id</param> | ||
/// <returns>A configured blob client</returns> | ||
public BlobContainerClient BuildContainerClient(string grainType, GrainReference grainId); | ||
|
||
/// <summary> | ||
/// Initialize any required dependenceis using the provided client and options | ||
/// </summary> | ||
/// <param name="client">The connected blob client</param> | ||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> | ||
public Task Init(BlobServiceClient client); | ||
} | ||
|
||
/// <summary> | ||
/// A default blob container factory that uses the default container name | ||
/// </summary> | ||
internal class DefaultBlobContainerFactory : IBlobContainerFactory | ||
{ | ||
private readonly AzureBlobStorageOptions _options; | ||
private BlobContainerClient _defaultContainer = null!; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DefaultBlobContainerFactory"/> class. | ||
/// </summary> | ||
/// <param name="options">The blob storage options</param> | ||
public DefaultBlobContainerFactory(AzureBlobStorageOptions options) | ||
{ | ||
_options = options; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public BlobContainerClient BuildContainerClient(string grainType, GrainReference grainId) | ||
=> _defaultContainer; | ||
|
||
/// <inheritdoc/> | ||
public async Task Init(BlobServiceClient client) | ||
{ | ||
_defaultContainer = client.GetBlobContainerClient(_options.ContainerName); | ||
await _defaultContainer.CreateIfNotExistsAsync(); | ||
} | ||
} |