Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keep the CloudBlobClient alive during application lifecycle with dependency injection

I want to dependency inject the CloudBlobContainer instance "container" into my custom class.

The question is the lifetime. I could do for Per Web Request or As a singleton because that client will never change when the application runs.

My question is should I expect problems because the blobClient keeps a kind of open connection?

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
ConfigurationManager.AppSettings["MyDataStorageConnectionString"]
);

CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mydata");
like image 475
Elisabeth Avatar asked Oct 02 '15 09:10

Elisabeth


1 Answers

IIRC, the Azure SDK gives you an object-oriented API that shields you from the communications details. The way you communicate with the Azure storage services is via HTTP (they're level 2 REST services), so keeping CloudBlobContainer object around doesn't keep a connection open.

I've never had problems keeping CloudBlobContainer objects around for the lifetime of a web application.

Still, according to the documentation, instance members aren't guaranteed to be thread-safe, so to be on the safe side, you should consider having an instance per web request.

like image 130
Mark Seemann Avatar answered Oct 05 '22 06:10

Mark Seemann