UA.Azure.Storage provides a lightweight, efficient implementation for accessing Azure Storage Services (Blob, Queue, and Table) in .NET applications. Built on the Tenet Framework principles, it offers a simplified agent-based approach to interact with Azure Storage without heavy SDK dependencies.
$ dotnet add package UA.Azure.StorageUA.Azure.Storage provides a lightweight, efficient implementation for accessing Azure Storage Services (Blob, Queue, and Table) in .NET applications. Built on the Tenet Framework principles, it offers a simplified agent-based approach to interact with Azure Storage without the overhead of heavy SDK dependencies.
Install via NuGet Package Manager:
dotnet add package UA.Azure.Storage
Or via Package Manager Console:
Install-Package UA.Azure.Storage
using UA.Azure.Storage.Blob;
using UA.Azure.Storage.Blob.Models;
// Initialize the blob agent
var blobAgent = new BlobAgent(connectionString, autoAssignRequestId: true);
// Create a container
await blobAgent.CreateContainerAsync(new ContainerRequest
{
Name = "my-container",
PublicAccess = PublicAccessType.Blob
});
// Upload a blob
await blobAgent.UploadBlobAsync(new BlobRequest
{
ContainerName = "my-container",
BlobName = "document.pdf",
Content = fileStream,
ContentType = "application/pdf"
});
// Download a blob
var blob = await blobAgent.GetBlobAsync("my-container", "document.pdf");
// List blobs in a container
var blobs = await blobAgent.ListBlobsAsync("my-container");
foreach (var blobItem in blobs.Items)
{
Console.WriteLine($"Blob: {blobItem.Name}, Size: {blobItem.Properties.ContentLength}");
}
// Delete a blob
await blobAgent.DeleteBlobAsync("my-container", "document.pdf");
using UA.Azure.Storage.Queue;
using UA.Azure.Storage.Queue.Models;
// Initialize the queue agent
var queueAgent = new QueueAgent(connectionString, autoAssignRequestId: true);
// Create a queue
await queueAgent.CreateQueueAsync(new QueueRequest { Name = "processing-queue" });
// Send a message
await queueAgent.SendMessageAsync(new MessageRequest
{
QueueName = "processing-queue",
MessageText = "Process order #12345",
VisibilityTimeout = TimeSpan.FromMinutes(5),
TimeToLive = TimeSpan.FromDays(7)
});
// Receive messages
var messages = await queueAgent.ReceiveMessagesAsync("processing-queue", maxMessages: 10);
foreach (var message in messages.Items)
{
Console.WriteLine($"Message: {message.MessageText}");
// Process the message...
// Delete the message after processing
await queueAgent.DeleteMessageAsync("processing-queue", message.MessageId, message.PopReceipt);
}
// Peek messages without dequeuing
var peekedMessages = await queueAgent.PeekMessagesAsync("processing-queue", maxMessages: 5);
using UA.Azure.Storage.Table;
using UA.Azure.Storage.Table.Models;
// Initialize the table agent
var tableAgent = new TableAgent(connectionString, autoAssignRequestId: true);
// Create a table
await tableAgent.CreateTableAsync("Customers");
// Insert an entity
var customer = new Dictionary<string, object>
{
["PartitionKey"] = "USA",
["RowKey"] = "customer001",
["Name"] = "John Doe",
["Email"] = "john@example.com",
["Age"] = 35
};
await tableAgent.InsertEntityAsync(new EntityRequest
{
TableName = "Customers",
Entity = customer
});
// Query entities
var query = new ODataQuery
{
Filter = "Age gt 30",
Select = new[] { "Name", "Email", "Age" },
Top = 100
};
var entities = await tableAgent.QueryEntitiesAsync("Customers", query);
// Update an entity
customer["Email"] = "john.doe@example.com";
await tableAgent.UpdateEntityAsync(new EntityRequest
{
TableName = "Customers",
Entity = customer,
ETag = "*" // Use specific ETag for optimistic concurrency
});
// Batch operations
var batchRequest = new BatchRequest
{
TableName = "Customers",
PartitionKey = "USA"
};
batchRequest.AddInsert(entity1);
batchRequest.AddUpdate(entity2);
batchRequest.AddDelete(entity3);
await tableAgent.ExecuteBatchAsync(batchRequest);
// Delete an entity
await tableAgent.DeleteEntityAsync("Customers", "USA", "customer001");
using UA.Azure.Storage.Blob.Models.Query;
// Query blob contents using SQL-like syntax
var queryRequest = new QueryRequest
{
QueryExpression = "SELECT * FROM BlobStorage WHERE Age > 25",
InputSerialization = new InputSerialization
{
Format = new JsonTextConfiguration
{
RecordSeparator = "\n"
}
},
OutputSerialization = new OutputSerialization
{
Format = new JsonTextConfiguration
{
RecordSeparator = "\n"
}
}
};
var result = await blobAgent.QueryBlobContentsAsync("my-container", "data.json", queryRequest);
UA.Azure.Storage is built on three main agent classes:
All agents inherit from StorageAgentBase, providing common functionality like:
// From appsettings.json
var connectionString = configuration.GetConnectionString("AzureStorage");
// Direct connection string
var connectionString = "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net";
var blobAgent = new BlobAgent(connectionString);
builder.Services.AddSingleton<BlobAgent>(sp =>
new BlobAgent(configuration.GetConnectionString("AzureStorage"), autoAssignRequestId: true));
builder.Services.AddSingleton<QueueAgent>(sp =>
new QueueAgent(configuration.GetConnectionString("AzureStorage"), autoAssignRequestId: true));
builder.Services.AddSingleton<TableAgent>(sp =>
new TableAgent(configuration.GetConnectionString("AzureStorage"), autoAssignRequestId: true));
UA.Azure.Storage is designed for performance:
For comprehensive documentation, tutorials, and API reference, visit:
Made with ❤️ by UA Devs @ Chiclana de la Frontera (Spain)