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");
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With