Implement azurite

This commit is contained in:
SergioMatias94 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) public static IServiceCollection AddBlobStorage(this IServiceCollection services, IConfiguration configuration)
{ {
var blobConnection = configuration.GetConnectionString("BlobStorage"); 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."); throw new ArgumentException("The BlobStorage configuration section is missing or empty.");
}
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? string.Empty;
services.AddAzureClients(cfg =>
{
if (environment == "Local")
{
cfg.AddBlobServiceClient(configuration.GetConnectionString("BlobStorage"));
}
else
{
var chainedCredentials = new ChainedTokenCredential( var chainedCredentials = new ChainedTokenCredential(
new ManagedIdentityCredential(), new ManagedIdentityCredential(),
new SharedTokenCacheCredential(), new SharedTokenCacheCredential(),
new VisualStudioCredential(), new VisualStudioCredential(),
new VisualStudioCodeCredential() new VisualStudioCodeCredential()
); );
services.AddAzureClients(cfg =>
{ cfg.AddBlobServiceClient(new Uri(blobConnection))
cfg.AddBlobServiceClient(new Uri(blobConnection)).WithCredential(chainedCredentials); .WithCredential(chainedCredentials);
}
}); });
services.AddScoped<IBlobStorageProvider, BlobStorageProvider>(); services.AddScoped<IBlobStorageProvider, BlobStorageProvider>();