Implement azurite

This commit is contained in:
2025-06-08 18:20:34 -06:00
parent a56818bcf8
commit eda79010ce

View File

@@ -11,23 +11,31 @@ namespace Core.Blueprint.Storage.Configuration
{
public static IServiceCollection AddBlobStorage(this IServiceCollection services, IConfiguration configuration)
{
var blobConnection = configuration.GetConnectionString("BlobStorage");
if (blobConnection == null || string.IsNullOrWhiteSpace(blobConnection))
{
if (string.IsNullOrWhiteSpace(blobConnection))
throw new ArgumentException("The BlobStorage configuration section is missing or empty.");
}
var chainedCredentials = new ChainedTokenCredential(
new ManagedIdentityCredential(),
new SharedTokenCacheCredential(),
new VisualStudioCredential(),
new VisualStudioCodeCredential()
);
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty;
services.AddAzureClients(cfg =>
{
cfg.AddBlobServiceClient(new Uri(blobConnection)).WithCredential(chainedCredentials);
if (environment == "Local")
{
cfg.AddBlobServiceClient(configuration.GetConnectionString("BlobStorage"));
}
else
{
var chainedCredentials = new ChainedTokenCredential(
new ManagedIdentityCredential(),
new SharedTokenCacheCredential(),
new VisualStudioCredential(),
new VisualStudioCodeCredential()
);
cfg.AddBlobServiceClient(new Uri(blobConnection))
.WithCredential(chainedCredentials);
}
});
services.AddScoped<IBlobStorageProvider, BlobStorageProvider>();