Add project files.
This commit is contained in:
38
Core.Blueprint.Storage/Configuration/RegisterBlueprint.cs
Normal file
38
Core.Blueprint.Storage/Configuration/RegisterBlueprint.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Azure.Identity;
|
||||
using Core.Blueprint.Storage.Contracts;
|
||||
using Core.Blueprint.Storage.Provider;
|
||||
using Microsoft.Extensions.Azure;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Core.Blueprint.Storage.Configuration
|
||||
{
|
||||
public static class RegisterBlueprint
|
||||
{
|
||||
public static IServiceCollection AddBlobStorage(this IServiceCollection services, IConfiguration configuration)
|
||||
{
|
||||
|
||||
var blobConnection = configuration.GetConnectionString("BlobStorage");
|
||||
|
||||
if (blobConnection == null || 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()
|
||||
);
|
||||
services.AddAzureClients(cfg =>
|
||||
{
|
||||
cfg.AddBlobServiceClient(new Uri(blobConnection)).WithCredential(chainedCredentials);
|
||||
});
|
||||
|
||||
services.AddScoped<IBlobStorageProvider, BlobStorageProvider>();
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user