私は、ユーザーが画像をアップロードすることができ、私はAzureブロブに格納するWeb APIプロジェクトを持っています。コードは次のとおりです。Azure Blobコンテナスレッドセーフ?
public class AzureImageHandler : IImageHandler
{
public async Task<string> StoreImage(byte[] image)
{
var storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
var blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("images");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
container.SetPermissions(
new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Retrieve reference to a blob named "myblob".
var blockBlob = container.GetBlockBlobReference("myblob");
await blockBlob.UploadFromByteArrayAsync(image, 0, image.Length);
return blockBlob.Uri.ToString();
}
}
私はDIをAutofacを使用してセットアップしていますが、いずれかのコードがスレッドセーフであるかどうか疑問に思っています。つまり、すべての要求が新しいBLOBへの参照を取得するために使用するシングルトンコンテナを持つことはできますか?またはこのメソッド全体を毎回実行する必要がありますか? CloudStorageAccount/BlobClient/Containerがスレッドセーフであるかどうかはわかりませんでした。 CloudBlobContainer
クラスのドキュメントから
おかげ