Expose API on AzureStorageResource to get the emulator connection string

Open Beginner friendly
#6,234 3 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Quiet
Tech stack
azure, csharp
Domain
cloud

Research direction

Start in src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs at the internal emulator connection-string method linked in the issue. Expose the proposed EmulatorConnectionString property and verify that the provided Azure Storage Explorer usage can consume it when IsEmulator is true.

Written by the indexing model from the issue text.

Description

area-integrations azure azure-storage

Background and Motivation

There are scenarios where resource want to get the full emulator connection string from the Azure storage emulator (Azurite) resource. We have an internal method today

https://github.com/dotnet/aspire/blob/b51d08a617a60ae30f8305d98f1e34e1ed90da1a/src/Aspire.Hosting.Azure.Storage/AzureStorageResource.cs#L49

Proposed API

namespace Aspire.Hosting;

public class AzureStorageResource
{
+    public ReferenceExpression EmulatorConnectionString { get; }
}

Usage Examples

var storage = builder.AddAzureStorage("storage")
                   .RunAsEmulator();
var blobs = storage.AddBlobs("blobs");

if (storage.Resource.IsEmulator)
{
    // Add the Azure Storage Explorer container when running in the emulator

    builder.AddContainer("storage-explorer", "sebagomez/azurestorageexplorer")
        .WithHttpEndpoint(targetPort: 8080)
        .WithEnvironment("AZURE_STORAGE_CONNECTIONSTRING", storage.Resource.EmulatorConnectionString);
}

Alternative Designs

We could make AzureStorageResource implement IResourceWithConnectionString and do the same. It would only work if IsEmulator was true.

+ public class AzureStorageResource : IResourceWithConnectionString
{
+    public ReferenceExpression ConnectionStringExpression => IsEmulator ? ... : throw new NotSupportedException(...);
}
var storage = builder.AddAzureStorage("storage")
                   .RunAsEmulator();
var blobs = storage.AddBlobs("blobs");

if (storage.Resource.IsEmulator)
{
    // Add the Azure Storage Explorer container when running in the emulator

    builder.AddContainer("storage-explorer", "sebagomez/azurestorageexplorer")
        .WithHttpEndpoint(targetPort: 8080)
        .WithEnvironment("AZURE_STORAGE_CONNECTIONSTRING", storage);
}

Risks

None

Dominant language
C#
Stars
6.3k
Forks
992
Avg merge
2d 16h
Merged PRs (30d)
176

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/aspire

All issues in microsoft/aspire

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.