Skip to content

ERNI-Academy/assets-cloud-storage-abstraction

Repository files navigation

About

Azure Blob storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data. Unstructured data is data that doesn't adhere to a particular data model or definition, such as text or binary data.

About Blob storage Blob storage is designed for:

  • Serving images or documents directly to a browser.
  • Storing files for distributed access.
  • Streaming video and audio.
  • Writing to log files.
  • Storing data for backup and restore, disaster recovery, and archiving.
  • Storing data for analysis by an on-premises or Azure-hosted service.

Cloud Storage Abstraction is a small dll ( on the next iteration, it will be a nuget package) that provides a robust and reusable implementations.

With this package we standardize the usage and implementation of Azure Storage Blobs in all your code.

With this implementation you have both publish and subscriber clients available at one sight.

All Contributors

Built With

Features

  • Create Container
  • Upload Blob
  • Get list of blobs
  • Get concrete blob
  • Delete blob

Getting Started

At this point, we have to use this project like dll or directly on our production projects.

On next releases, we transform the solution into nuget.

Pre-requisites

Dependencies

  • Newtonsoft
  • Azure.Storage.Blob v12
  • .Net 6.0
  • System.Text.Json

Installation

git clone https://github.com/ERNI-Academy/assets-cloud-storage-abstraction.git

Object definitions

IBlobContainerClient

That contract contains all methods to manage a default CRUD.

    public interface IBlobContainerClient
    {
        string GetConnectionString();
        Task<Azure.Storage.Blobs.BlobContainerClient> CreateContainerIfNotExist(string name = "");
        Task<string> UploadBlob(string id, object blob, string containerName);
        Task<object> Get(Guid id, string containerId);
        IEnumerable<object> Get(string containerId);
        Task<bool> RemoveBlob(Guid id, string containerId);
    }

BlobContainerClient

That is the main implementation. It is the client to manage the CRUD operations with a concrete blob container.

    public class BlobContainerClient : ContainerClientBase, IBlobContainerClient
    {
        private BlobServiceClient serviceClient;
        public BlobContainerClient(IContainerServiceConfig config) : base(config){}
        ...
    }

IContainerServiceConfig

That contract specify the only way to assign a connectionstring to the BlobContainerClient

   public interface IContainerServiceConfig
   {
        string GetConnectionString();
   }

ContainerServiceDevelopmentConfig

That implementation has the purpose to be used only to development environments. If you are developing and you want to use the local emulator, you could use that implementation. but take care, that approach never can be used on production

   public class ContainerServiceDevelopmentConfig : IContainerServiceConfig
   {
        public string GetConnectionString()
        {
            return "UseDevelopmentStorage=true";
        }
   }

Notes

  • the interface IContainerServiceConfig has a default implementation that is forbidden use it on production. ALWAYS RETURN a connection string for the Azure Storage Emulator.
  • You should implement your own class where you could manage your proper connectionstring

samples

In order to run this sample, you need to have Azure Blob Storage Emulator

 IContainerServiceConfig config = new ContainerServiceDevelopmentConfig();
 Console.WriteLine($"ConnectionString used: {config.GetConnectionString()}");
 Console.WriteLine("first sample about upload an object");
 IBlobContainerClient blobClient = new BlobContainerClient(config);
 var obj = new { name = "Smith", age = 38 };
 Guid id = Guid.NewGuid();
 string containerName = "localcontainer";
 Console.WriteLine($"object used: {obj}");
 var blobLink = blobClient.UploadBlob(id.ToString(), obj, containerName).Result;
 Console.WriteLine($"Http code response: {blobLink}");
  • take care about that sample are instances directly. In general situation, we should use DI.

Contributing

Please see our Contribution Guide to learn how to contribute.

License

MIT

(LICENSE) Β© 2022 ERNI - Swiss Software Engineering

Code of conduct

Please see our Code of Conduct

Stats

Alt

Follow us

Twitter Follow Twitch Status YouTube Channel Views Linkedin

Contact

πŸ“§ esp-services@betterask.erni

Manu Delgado - @mdelgadodiaz83 - mdelgadodiaz83@gmail.com

Contributors ✨

Thanks goes to these wonderful people (emoji key):


omaramalfi

πŸ’» πŸ–‹ πŸ“– 🎨 πŸ€” 🚧 ⚠️ πŸ’‘ πŸ‘€

mdelgadodiaz83-erni

πŸ’» πŸ–‹ πŸ“– 🎨 πŸ€” 🚧 ⚠️ πŸ’‘ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

About

With this package we standardize the usage and implementation of Azure Storage Blobs in all your code.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Contributors 4

  •  
  •  
  •  
  •  

Languages