Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,15 @@

var builder = DistributedApplication.CreateBuilder(args);

var storage = builder.AddAzureStorage("storage").RunAsEmulator(container =>
{
container.WithDataBindMount();
});
var storage = builder.AddAzureStorage("storage");

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

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

var storage2 = builder.AddAzureStorage("storage2").RunAsEmulator(container =>
{
container.WithDataBindMount();
});
var storage2 = builder.AddAzureStorage("storage2");

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

Expand All @@ -38,4 +32,3 @@
#endif

builder.Build().Run();

4 changes: 2 additions & 2 deletions playground/bicep/BicepSample.AppHost/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

var kv = builder.AddAzureKeyVault("kv3");
var appConfig = builder.AddAzureAppConfiguration("appConfig").WithParameter("sku", "standard");
var storage = builder.AddAzureStorage("storage");
// .RunAsEmulator();
var storage = builder.AddAzureStorage("storage")
.RunAsEmulator();

var blobs = storage.AddBlobs("blob");
var tables = storage.AddTables("table");
Expand Down
33 changes: 30 additions & 3 deletions src/Aspire.Hosting.Azure/AzureEnvironmentResourceExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#pragma warning disable ASPIREAZURE001 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;
using Microsoft.Extensions.DependencyInjection;

namespace Aspire.Hosting.Azure;

Expand Down Expand Up @@ -34,10 +38,33 @@ public static IResourceBuilder<AzureEnvironmentResource> AddAzureEnvironment(thi
var resource = new AzureEnvironmentResource(resourceName, locationParam, resourceGroupName, principalId);
if (builder.ExecutionContext.IsRunMode)
{
// Return a builder that isn't added to the top-level application builder
// so it doesn't surface as a resource.
return builder.CreateResourceBuilder(resource);
var resourceBuilder = builder.AddResource(resource)
.WithInitialState(new CustomResourceSnapshot
{
ResourceType = nameof(AzureEnvironmentResource),
CreationTimeStamp = DateTime.UtcNow,
State = KnownResourceStates.NotStarted,
Properties = ImmutableArray<ResourcePropertySnapshot>.Empty
});

foreach (var command in AzureProvisioningController.EnvironmentCommandDefinitions)
{
resourceBuilder.WithCommand(
command.Name,
command.DisplayName,
executeCommand: context => context.ServiceProvider.GetRequiredService<AzureProvisioningController>().ExecuteEnvironmentCommandAsync(command.Command, context),
commandOptions: new CommandOptions
{
Description = command.Description,
ConfirmationMessage = command.ConfirmationMessage,
IconName = command.IconName,
IconVariant = command.IconVariant,
IsHighlighted = command.IsHighlighted,
UpdateState = context => context.ServiceProvider.GetRequiredService<AzureProvisioningController>().GetEnvironmentCommandState()
});
}

return resourceBuilder.ExcludeFromManifest();
}

// In publish mode, add the resource to the application model
Expand Down
Loading
Loading