Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion playground/AspireEventHub/EventHubs.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// required for the event processor client which will use the connectionName to get the connectionString.
var blob = builder.AddAzureStorage("ehstorage")
.RunAsEmulator()
.AddBlobs("checkpoints");
.AddBlobService("checkpoints");

var eventHub = builder.AddAzureEventHubs("eventhubns")
.RunAsEmulator()
Expand Down
2 changes: 1 addition & 1 deletion playground/AspireEventHub/EventHubsConsumer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
else
{
// required for checkpointing our position in the event stream
builder.AddAzureBlobClient("checkpoints");
builder.AddAzureBlobServiceClient("checkpoints");

builder.AddAzureEventProcessorClient("eventhubOne");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
builder.AddServiceDefaults();

builder.AddCosmosDbContext<TestCosmosContext>("account", "db");
builder.AddAzureBlobClient("blobs");
builder.AddAzureBlobServiceClient("blobs");

var app = builder.Build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
storage.AllowBlobPublicAccess = false;
})
.RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent));
var blobs = storage.AddBlobs("blobs");
var blobs = storage.AddBlobService("blobs");

// Testing projects
builder.AddProject<Projects.AzureAppService_ApiService>("api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
builder.AddServiceDefaults();

builder.AddCosmosDbContext<TestCosmosContext>("account", "db");
builder.AddAzureBlobClient("blobs");
builder.AddAzureBlobServiceClient("blobs");
builder.AddRedisClient("cache");

var app = builder.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// Testing a connection string
var storage = builder.AddAzureStorage("storage")
.RunAsEmulator(c => c.WithLifetime(ContainerLifetime.Persistent));
var blobs = storage.AddBlobs("blobs");
var blobs = storage.AddBlobService("blobs");

// Testing docker files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

// Add service defaults & Aspire client integrations.
builder.AddServiceDefaults();
builder.AddAzureQueueClient("queue");
builder.AddAzureBlobClient("blob");
builder.AddAzureQueueServiceClient("queue");
builder.AddAzureBlobServiceClient("blob");
builder.AddAzureEventHubProducerClient("myhub");
#if !SKIP_UNSTABLE_EMULATORS
builder.AddAzureServiceBusClient("messaging");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
builder.AddAzureContainerAppEnvironment("env");

var storage = builder.AddAzureStorage("storage").RunAsEmulator();
var queue = storage.AddQueues("queue");
var blob = storage.AddBlobs("blob");
var myBlobContainer = blob.AddBlobContainer("myblobcontainer");
var queue = storage.AddQueueService("queue");
var blob = storage.AddBlobService("blob");
var myBlobContainer = storage.AddBlobContainer("myblobcontainer");

var eventHub = builder.AddAzureEventHubs("eventhubs")
.RunAsEmulator()
Expand All @@ -24,11 +24,11 @@
var funcApp = builder.AddAzureFunctionsProject<Projects.AzureFunctionsEndToEnd_Functions>("funcapp")
.WithExternalHttpEndpoints()
.WithReference(eventHub).WaitFor(eventHub)
.WithReference(myBlobContainer).WaitFor(myBlobContainer)
#if !SKIP_UNSTABLE_EMULATORS
.WithReference(serviceBus).WaitFor(serviceBus)
.WithReference(cosmosDb).WaitFor(cosmosDb)
#endif
.WithReference(myBlobContainer).WaitFor(myBlobContainer)
.WithReference(blob)
.WithReference(queue);

Expand All @@ -39,6 +39,7 @@
.WithReference(serviceBus).WaitFor(serviceBus)
.WithReference(cosmosDb).WaitFor(cosmosDb)
#endif
.WithReference(myBlobContainer).WaitFor(myBlobContainer)
.WithReference(queue)
.WithReference(blob)
.WithReference(funcApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace AzureFunctionsEndToEnd.Functions;

public class MyAzureBlobTrigger(ILogger<MyAzureBlobTrigger> logger, BlobContainerClient containerClient)
public class MyAzureBlobTrigger(BlobContainerClient containerClient, ILogger<MyAzureBlobTrigger> logger)
{
[Function(nameof(MyAzureBlobTrigger))]
[BlobOutput("test-files/{name}.txt", Connection = "blob")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class MyAzureQueueTrigger(ILogger<MyAzureQueueTrigger> logger)
{
[Function(nameof(MyAzureQueueTrigger))]
public void Run([QueueTrigger("queue", Connection = "queue")] QueueMessage message)
{
{
logger.LogInformation("C# Queue trigger function processed: {Text}", message.MessageText);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
var builder = FunctionsApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddAzureQueueClient("queue");
builder.AddAzureBlobClient("blob");
builder.AddAzureQueueServiceClient("queue");
builder.AddAzureBlobServiceClient("blob");
builder.AddAzureBlobContainerClient("myblobcontainer");
builder.AddAzureEventHubProducerClient("myhub");
#if !SKIP_UNSTABLE_EMULATORS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

builder.AddServiceDefaults();

builder.AddAzureBlobClient("blobs");
builder.AddAzureBlobServiceClient("blobs");

builder.AddKeyedAzureBlobContainerClient("foocontainer");

builder.AddAzureQueueClient("queues");
builder.AddKeyedAzureQueue("myqueue");

var app = builder.Build();

app.MapDefaultEndpoints();

app.MapGet("/", async (BlobServiceClient bsc, QueueServiceClient qsc, [FromKeyedServices("foocontainer")] BlobContainerClient keyedContainerClient1) =>
app.MapGet("/", async (BlobServiceClient bsc, [FromKeyedServices("myqueue")] QueueClient queue, [FromKeyedServices("foocontainer")] BlobContainerClient keyedContainerClient1) =>
{
var blobNames = new List<string>();
var blobNameAndContent = Guid.NewGuid().ToString();
Expand All @@ -30,8 +31,6 @@
await ReadBlobsAsync(directContainerClient, blobNames);
await ReadBlobsAsync(keyedContainerClient1, blobNames);

var queue = qsc.GetQueueClient("myqueue");
await queue.CreateIfNotExistsAsync();
await queue.SendMessageAsync("Hello, world!");

return blobNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
container.WithDataBindMount();
});

var blobs = storage.AddBlobs("blobs");
blobs.AddBlobContainer("mycontainer1", blobContainerName: "test-container-1");
blobs.AddBlobContainer("mycontainer2", blobContainerName: "test-container-2");
var blobs = storage.AddBlobService("blobs");
storage.AddBlobContainer("mycontainer1", blobContainerName: "test-container-1");
storage.AddBlobContainer("mycontainer2", blobContainerName: "test-container-2");

var queues = storage.AddQueues("queues");
var myqueue = storage.AddQueue("myqueue", queueName: "my-queue");

var storage2 = builder.AddAzureStorage("storage2").RunAsEmulator(container =>
{
container.WithDataBindMount();
});
var blobs2 = storage2.AddBlobs("blobs2");
var blobContainer2 = blobs2.AddBlobContainer("foocontainer", blobContainerName: "foo-container");

var blobContainer2 = storage2.AddBlobContainer("foocontainer", blobContainerName: "foo-container");

builder.AddProject<Projects.AzureStorageEndToEnd_ApiService>("api")
.WithExternalHttpEndpoints()
.WithReference(blobs).WaitFor(blobs)
.WithReference(blobContainer2).WaitFor(blobContainer2)
.WithReference(queues).WaitFor(queues);
.WithReference(myqueue).WaitFor(myqueue);

#if !SKIP_DASHBOARD_REFERENCE
// This project is only added in playground projects to support development/debugging
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
"type": "value.v0",
"connectionString": "{storage.outputs.blobEndpoint}"
},
"storage-blobs": {
"type": "value.v0",
"connectionString": "{storage.outputs.blobEndpoint}"
},
"mycontainer1": {
"type": "value.v0",
"connectionString": "Endpoint={storage.outputs.blobEndpoint};ContainerName=test-container-1"
Expand All @@ -29,6 +33,10 @@
"type": "value.v0",
"connectionString": "{storage2.outputs.blobEndpoint}"
},
"storage2-blobs": {
"type": "value.v0",
"connectionString": "{storage2.outputs.blobEndpoint}"
},
"foocontainer": {
"type": "value.v0",
"connectionString": "Endpoint={storage2.outputs.blobEndpoint};ContainerName=foo-container"
Expand All @@ -42,7 +50,6 @@
"OTEL_DOTNET_EXPERIMENTAL_OTLP_RETRY": "in_memory",
"ASPNETCORE_FORWARDEDHEADERS_ENABLED": "true",
"HTTP_PORTS": "{api.bindings.http.targetPort}",
"ConnectionStrings__blobs": "{blobs.connectionString}",
"ConnectionStrings__foocontainer": "{foocontainer.connectionString}",
"ConnectionStrings__queues": "{queues.connectionString}"
},
Expand Down
6 changes: 3 additions & 3 deletions playground/bicep/BicepSample.ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
builder.AddNpgsqlDbContext<MyPgDbContext>("db2");
builder.AddAzureCosmosClient("cosmos");
builder.AddRedisClient("redis");
builder.AddAzureBlobClient("blob");
builder.AddAzureTableClient("table");
builder.AddAzureQueueClient("queue");
builder.AddAzureBlobServiceClient("blob");
builder.AddAzureTableServiceClient("table");
builder.AddAzureQueueServiceClient("queue");
builder.AddAzureServiceBusClient("sb");

var app = builder.Build();
Expand Down
6 changes: 3 additions & 3 deletions playground/bicep/BicepSample.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
var storage = builder.AddAzureStorage("storage");
// .RunAsEmulator();

var blobs = storage.AddBlobs("blob");
var tables = storage.AddTables("table");
var queues = storage.AddQueues("queue");
var blobs = storage.AddBlobService("blob");
var tables = storage.AddTableService("table");
var queues = storage.AddQueueService("queue");

var sqlServer = builder.AddAzureSqlServer("sql").AddDatabase("db");

Expand Down
2 changes: 1 addition & 1 deletion playground/cdk/CdkSample.ApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

builder.AddServiceDefaults();

builder.AddAzureBlobClient("blobs");
builder.AddAzureBlobServiceClient("blobs");
builder.AddSqlServerDbContext<SqlContext>("sqldb");
builder.AddAzureKeyVaultClient("mykv");
builder.AddRedisClient("cache");
Expand Down
2 changes: 1 addition & 1 deletion playground/cdk/CdkSample.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
account.Location = locationOverride.AsProvisioningParameter(infrastructure);
});

var blobs = storage.AddBlobs("blobs");
var blobs = storage.AddBlobService("blobs");

var sqldb = builder.AddAzureSqlServer("sql").AddDatabase("sqldb");

Expand Down
4 changes: 2 additions & 2 deletions playground/orleans/Orleans.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var builder = DistributedApplication.CreateBuilder(args);

var storage = builder.AddAzureStorage("storage").RunAsEmulator();
var clusteringTable = storage.AddTables("clustering");
var grainStorage = storage.AddBlobs("grainstate");
var clusteringTable = storage.AddTableService("clustering");
var grainStorage = storage.AddBlobService("grainstate");

var orleans = builder.AddOrleans("my-app")
.WithClustering(clusteringTable)
Expand Down
2 changes: 1 addition & 1 deletion playground/orleans/OrleansClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddKeyedAzureTableClient("clustering");
builder.AddKeyedAzureTableServiceClient("clustering");
builder.UseOrleansClient();

var app = builder.Build();
Expand Down
4 changes: 2 additions & 2 deletions playground/orleans/OrleansServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
var builder = WebApplication.CreateBuilder(args);

builder.AddServiceDefaults();
builder.AddKeyedAzureTableClient("clustering");
builder.AddKeyedAzureBlobClient("grainstate");
builder.AddKeyedAzureTableServiceClient("clustering");
builder.AddKeyedAzureBlobServiceClient("grainstate");
builder.UseOrleans();

var app = builder.Build();
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Hosting.Azure.Functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ using Aspire.Hosting.Azure.Functions;
var builder = new DistributedApplicationBuilder();

var storage = builder.AddAzureStorage("storage").RunAsEmulator();
var queue = storage.AddQueues("queue");
var blob = storage.AddBlobs("blob");
var queue = storage.AddQueueService("queue");
var blob = storage.AddBlobService("blob");

builder.AddAzureFunctionsProject<Projects.Company_FunctionApp>("my-functions-project")
.WithReference(queue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" />
<PackageReference Include="AspNetCore.HealthChecks.Azure.Storage.Blobs" />
<PackageReference Include="AspNetCore.HealthChecks.Azure.Storage.Queues" />
<PackageReference Include="Azure.Provisioning" />
<PackageReference Include="Azure.Provisioning.Storage" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void IResourceWithAzureFunctionsConfig.ApplyAzureFunctionsConfiguration(IDiction
target[$"{connectionName}__queueServiceUri"] = Parent.QueueEndpoint;

// Injected to support Aspire client integration for Azure Storage.
// We don't inject the queue resource here since we on;y want it to
// We don't inject the queue resource here since we only want it to
// be accessible by the Functions host.
target[$"{AzureStorageResource.BlobsConnectionKeyPrefix}__{connectionName}__ServiceUri"] = Parent.BlobEndpoint;
}
Expand Down
55 changes: 55 additions & 0 deletions src/Aspire.Hosting.Azure.Storage/AzureQueueStorageQueueResource.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Aspire.Hosting.ApplicationModel;
using Azure.Provisioning;

namespace Aspire.Hosting.Azure;

/// <summary>
/// A resource that represents an Azure Storage Queue.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="queueName">The name of the queue.</param>
/// <param name="parent">The <see cref="AzureQueueStorageResource"/> that the resource is stored in.</param>
public class AzureQueueStorageQueueResource(string name, string queueName, AzureQueueStorageResource parent) : Resource(name),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this (and blob container) implement IResourceWithAzureFunctionsConfig?

IResourceWithConnectionString,
IResourceWithParent<AzureQueueStorageResource>
{
/// <summary>
/// Gets the blob container name.
/// </summary>
public string QueueName { get; } = ThrowIfNullOrEmpty(queueName);

/// <summary>
/// Gets the connection string template for the manifest for the Azure Storage Queue resource.
/// </summary>
public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(QueueName);

/// <summary>
/// Gets the parent <see cref="AzureQueueStorageResource"/> of this <see cref="AzureQueueStorageQueueResource"/>.
/// </summary>
public AzureQueueStorageResource Parent => parent ?? throw new ArgumentNullException(nameof(parent));

/// <summary>
/// Converts the current instance to a provisioning entity.
/// </summary>
/// <returns>A <see cref="global::Azure.Provisioning.Storage.BlobContainer"/> instance.</returns>
internal global::Azure.Provisioning.Storage.StorageQueue ToProvisioningEntity()
{
global::Azure.Provisioning.Storage.StorageQueue queue = new(Infrastructure.NormalizeBicepIdentifier(Name))
{
Name = QueueName
};

return queue;
}

private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
ArgumentException.ThrowIfNullOrEmpty(argument, paramName);
return argument;
}
}
Loading