Implement azurite
This commit is contained in:
parent
a56818bcf8
commit
eda79010ce
@ -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>();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user