Skip to content

Add a clean way to use an existing BlobContainerClient #79

@karl-sjogren

Description

@karl-sjogren

I've been trying to setup Umbraco using .NET Aspire which sets up a BlobContainerClient with some extra telemetry attached. After looking at this for quite some time I managed to find a way to use that client with Umbraco like this.

public class PostConfigureAzureBlobFileSystemOptions : IPostConfigureOptions<AzureBlobFileSystemOptions> {
    private readonly BlobContainerClient _blobContainerClient;

    public PostConfigureAzureBlobFileSystemOptions(BlobContainerClient blobContainerClient) {
        _blobContainerClient = blobContainerClient;
    }

    public void PostConfigure(string? name, AzureBlobFileSystemOptions options) {
        ArgumentNullException.ThrowIfNull(options);

        options.ConnectionString = "https://not.a.real.storage.account.blob.core.windows.net/";
        options.TryCreateBlobContainerClientUsingUri(_ => _blobContainerClient);
    }
}

This does however look super hacky since I need to set the ConnectionString property to a "valid" url for the TryCreateBlobContainerClientUsingUri callback to be called :)

I'm not sure how to do this in the cleanest way though. I would love if there was some way to just take the BlobContainerClient directly from DI if available, maybe through another extension method on IUmbracoBuilder or just a settable option on AzureBlobFileSystemOptions?

At least adding a TryCreateBlobContainerClient method would be helpful so I can remove my ugly ConnectionString :)

I would be willing to contribute a PR for this, either for a simple new extension method or something even more helpful to get the BlobContainer from DI.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions