microsoft / microsoft/aspire

Expose API on AzureStorageResource to get the emulator connection string

Open
#6,234 3 comments 10 reactions 0 assignees View on GitHub
area-integrations azure azure-storage
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

## 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

```diff
namespace Aspire.Hosting;

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

## Usage Examples

```csharp
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.

```diff
+ public class AzureStorageResource : IResourceWithConnectionString
{
+ public ReferenceExpression ConnectionStringExpression => IsEmulator ? ... : throw new NotSupportedException(...);
}
```

```csharp
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.