Class AzureBlobStorageProvider
- Namespace
- CloudStorageORM.Providers.Azure.StorageProviders
- Assembly
- CloudStorageORM.dll
Azure Blob Storage implementation of IStorageProvider.
public class AzureBlobStorageProvider : IStorageProvider
- Inheritance
-
AzureBlobStorageProvider
- Implements
- Inherited Members
Constructors
AzureBlobStorageProvider(BlobContainerClient)
Creates a new Azure Blob Storage provider using an existing container client.
public AzureBlobStorageProvider(BlobContainerClient blobServiceClient)
Parameters
blobServiceClientBlobContainerClientThe container client to use for storage operations.
Examples
var provider = new AzureBlobStorageProvider(containerClient);
AzureBlobStorageProvider(CloudStorageOptions)
Creates a new Azure Blob Storage provider from CloudStorageORM options.
public AzureBlobStorageProvider(CloudStorageOptions options)
Parameters
optionsCloudStorageOptionsValidated CloudStorageORM options containing the Azure connection string and container name.
Examples
var provider = new AzureBlobStorageProvider(options);
AzureBlobStorageProvider(string, string)
Creates a new Azure Blob Storage provider from a connection string and container name.
public AzureBlobStorageProvider(string connectionString, string containerName)
Parameters
Examples
var provider = new AzureBlobStorageProvider("UseDevelopmentStorage=true", "app-data");
Properties
CloudProvider
Gets the cloud provider represented by this storage implementation.
public CloudProvider CloudProvider { get; }
Property Value
Methods
CreateContainerIfNotExistsAsync()
Creates the container or bucket if it does not already exist.
public Task CreateContainerIfNotExistsAsync()
Returns
Examples
await storageProvider.CreateContainerIfNotExistsAsync();
DeleteAsync(string)
Deletes an object from storage without an ETag precondition.
public Task DeleteAsync(string path)
Parameters
pathstringObject path inside the container.
Returns
Examples
await storageProvider.DeleteAsync("users/42.json");
DeleteAsync(string, string?)
Deletes an object from storage using an optional ETag precondition.
public Task DeleteAsync(string path, string? ifMatchETag)
Parameters
pathstringObject path inside the container.
ifMatchETagstringExpected ETag value used for optimistic concurrency.
Returns
Examples
await storageProvider.DeleteAsync("users/42.json", currentEtag);
DeleteContainerAsync()
Deletes the underlying container or bucket when it exists.
public Task DeleteContainerAsync()
Returns
Examples
await storageProvider.DeleteContainerAsync();
ListAsync(string)
Lists object paths under a folder-like prefix.
public Task<List<string>> ListAsync(string folderPath)
Parameters
folderPathstringFolder or prefix to search.
Returns
Examples
var keys = await storageProvider.ListAsync("users/");
ListPageAsync(string, int, string?, CancellationToken)
Lists object paths under a folder-like prefix as a single page with continuation support.
public Task<StorageListPage> ListPageAsync(string folderPath, int pageSize, string? continuationToken, CancellationToken cancellationToken = default)
Parameters
folderPathstringFolder or prefix to search.
pageSizeintMaximum number of keys to return for this page.
continuationTokenstringContinuation token returned by a previous call, if any.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<StorageListPage>
A page of keys and continuation information.
Examples
var page = await storageProvider.ListPageAsync("users/", 100, null);
ReadAsync<T>(string)
Reads and deserializes an entity payload from object storage.
public Task<T> ReadAsync<T>(string path)
Parameters
pathstringObject path inside the container.
Returns
- Task<T>
The deserialized entity payload.
Type Parameters
TEntity payload type to deserialize.
Examples
var user = await storageProvider.ReadAsync<User>("users/42.json");
ReadWithMetadataAsync<T>(string)
Reads an entity payload and its metadata from object storage.
public Task<StorageObject<T>> ReadWithMetadataAsync<T>(string path)
Parameters
pathstringObject path inside the container.
Returns
- Task<StorageObject<T>>
A wrapper containing the entity value, ETag, and existence status.
Type Parameters
TEntity payload type to deserialize.
Examples
var result = await storageProvider.ReadWithMetadataAsync<User>("users/42.json");
if (result.Exists) { Console.WriteLine(result.ETag); }
SanitizeBlobName(string)
Sanitizes a raw blob name so it can be safely used by the provider.
public string SanitizeBlobName(string rawName)
Parameters
rawNamestringOriginal blob or folder name.
Returns
- string
Provider-safe normalized name.
Examples
var safeName = storageProvider.SanitizeBlobName("My Entity");
SaveAsync<T>(string, T)
Persists an entity payload at the specified path without an ETag precondition.
public Task SaveAsync<T>(string path, T entity)
Parameters
pathstringObject path inside the container.
entityTEntity payload to store.
Returns
Type Parameters
TEntity payload type to serialize.
Examples
await storageProvider.SaveAsync("users/42.json", user);
SaveAsync<T>(string, T, string?)
Persists an entity payload using an optional ETag precondition and returns the resulting ETag.
public Task<string?> SaveAsync<T>(string path, T entity, string? ifMatchETag)
Parameters
pathstringObject path inside the container.
entityTEntity payload to store.
ifMatchETagstringExpected ETag value used for optimistic concurrency.
Returns
Type Parameters
TEntity payload type to serialize.
Examples
var newEtag = await storageProvider.SaveAsync("users/42.json", user, currentEtag);