ManagedCode.Storage.Core 1.1.1

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package ManagedCode.Storage.Core --version 1.1.1                
NuGet\Install-Package ManagedCode.Storage.Core -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ManagedCode.Storage.Core" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ManagedCode.Storage.Core --version 1.1.1                
#r "nuget: ManagedCode.Storage.Core, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ManagedCode.Storage.Core as a Cake Addin
#addin nuget:?package=ManagedCode.Storage.Core&version=1.1.1

// Install ManagedCode.Storage.Core as a Cake Tool
#tool nuget:?package=ManagedCode.Storage.Core&version=1.1.1                

img|300x200

ManagedCode.Storage

.NET Coverage Status nuget CodeQL

Version Package Description
NuGet Package ManagedCode.Storage.Core Core
NuGet Package ManagedCode.Storage.FileSystem FileSystem
NuGet Package ManagedCode.Storage.Azure Azure
NuGet Package ManagedCode.Storage.Aws AWS
NuGet Package ManagedCode.Storage.Gcp GCP
NuGet Package ManagedCode.Storage.AspNetExtensions AspNetExtensions

Storage


Storage pattern implementation for C#.

A universal storage for working with multiple storage providers:

  • Azure
  • Google Cloud
  • Amazon
  • FileSystem

General concept

The library incapsulates all provider specific to make connection and managing storages as easy as possible. You have as customer just connect the library in your Startup providing necessary connection strings and inject needed interfaces in your services.

Connection modes

You can connect storage interface in two modes provider-specific and default. In case of default you are restricted with one storage type

Azure

Default mode connection:

// Startup.cs
services.AddAzureStorageAsDefault(new AzureStorageOptions
{
    Container = "{YOUR_CONTAINER_NAME}",
    ConnectionString = "{YOUR_CONNECTION_NAME}",
});

Using in default mode:

// MyService.cs
public class MyService
{
    private readonly IStorage _storage;

    public MyService(IStorage storage)
    {
        _storage = storage;
    }
}

Provider-specific mode connection:

// Startup.cs
services.AddAzureStorage(new AzureStorageOptions
{
    Container = "{YOUR_CONTAINER_NAME}",
    ConnectionString = "{YOUR_CONNECTION_NAME}",
});

Using in provider-specific mode

// MyService.cs
public class MyService
{
    private readonly IAzureStorage _azureStorage;

    public MyService(IAzureStorage azureStorage)
    {
        _azureStorage = azureStorage;
    }
}

<details> <summary>Google Cloud (Click here to expand)</summary>

Google Cloud

Default mode connection:

// Startup.cs
services.AddGCPStorageAsDefault(opt =>
{
    opt.GoogleCredential = GoogleCredential.FromFile("{PATH_TO_YOUR_CREDENTIALS_FILE}.json");

    opt.BucketOptions = new BucketOptions()
    {
        ProjectId = "{YOUR_API_PROJECT_ID}",
        Bucket = "{YOUR_BUCKET_NAME}",
    };
});

Using in default mode:

// MyService.cs
public class MyService
{
    private readonly IStorage _storage;
  
    public MyService(IStorage storage)
    {
        _storage = storage;
    }
}

Provider-specific mode connection:

// Startup.cs
services.AddGCPStorage(new GCPStorageOptions
{
    BucketOptions = new BucketOptions()
    {
        ProjectId = "{YOUR_API_PROJECT_ID}",
        Bucket = "{YOUR_BUCKET_NAME}",
    }
});

Using in provider-specific mode

// MyService.cs
public class MyService
{
    private readonly IGCPStorage _gcpStorage;
    public MyService(IGCPStorage gcpStorage)
    {
        _gcpStorage = gcpStorage;
    }
}

</details>

<details> <summary>Amazon (Click here to expand)</summary>

Amazon

Default mode connection:

// Startup.cs
//aws libarary overwrites property values. you should only create configurations this way. 
var awsConfig = new AmazonS3Config();
awsConfig.RegionEndpoint = RegionEndpoint.EUWest1;
awsConfig.ForcePathStyle = true;
awsConfig.UseHttp = true;
awsConfig.ServiceURL = "http://localhost:4566"; //this is the default port for the aws s3 emulator, must be last in the list

services.AddAWSStorageAsDefault(opt =>
{
    opt.PublicKey = "{YOUR_PUBLIC_KEY}";
    opt.SecretKey = "{YOUR_SECRET_KEY}";
    opt.Bucket = "{YOUR_BUCKET_NAME}";
    opt.OriginalOptions = awsConfig;
});

Using in default mode:

// MyService.cs
public class MyService
{
    private readonly IStorage _storage;
  
    public MyService(IStorage storage)
    {
        _storage = storage;
    }
}

Provider-specific mode connection:

// Startup.cs
services.AddAWSStorage(new AWSStorageOptions
{
    PublicKey = "{YOUR_PUBLIC_KEY}",
    SecretKey = "{YOUR_SECRET_KEY}",
    Bucket = "{YOUR_BUCKET_NAME}",
    OriginalOptions = awsConfig
});

Using in provider-specific mode

// MyService.cs
public class MyService
{
    private readonly IAWSStorage _gcpStorage;
    public MyService(IAWSStorage gcpStorage)
    {
        _gcpStorage = gcpStorage;
    }
}

</details>

<details> <summary>FileSystem (Click here to expand)</summary>

FileSystem

Default mode connection:

// Startup.cs
services.AddFileSystemStorageAsDefault(opt =>
{
    opt.CommonPath = Path.Combine(Environment.CurrentDirectory, "{YOUR_BUCKET_NAME}");
    opt.Path = "{YOUR_BUCKET_NAME}";
});

Using in default mode:

// MyService.cs
public class MyService
{
    private readonly IStorage _storage;
  
    public MyService(IStorage storage)
    {
        _storage = storage;
    }
}

Provider-specific mode connection:

// Startup.cs
services.AddFileSystemStorage(new FileSystemStorageOptions
{
    CommonPath = Path.Combine(Environment.CurrentDirectory, "{YOUR_BUCKET_NAME}"),
    Path = "{YOUR_BUCKET_NAME}"
});

Using in provider-specific mode

// MyService.cs
public class MyService
{
    private readonly IFileSystemStorage _fileSystemStorage;
    public MyService(IFileSystemStorage fileSystemStorage)
    {
        _fileSystemStorage = fileSystemStorage;
    }
}

</details>

How to use

We assume that below code snippets are placed in your service class with injected IStorage:

public class MyService
{
    private readonly IStorage _storage;
    public MyService(IStorage storage)
    {
        _storage = storage;
    }
}

Exists

await _storage.ExistsAsync("{YOUR_FILE_NAME}");

Delete

await _storage.DeleteAsync("{YOUR_FILE_NAME}");

Download

var stream = await _storage.DownloadAsStreamAsync(new BlobMetadata { Name = "{YOUR_FILE_NAME}"});
using var sr = new StreamReader(stream, Encoding.UTF8);

string content = await sr.ReadToEndAsync();

Get

await _storage.GetBlobAsync("{YOUR_FILE_NAME}");

Upload

var byteArray = Encoding.ASCII.GetBytes("{YOUR_CONTENT}");
var stream = new MemoryStream(byteArray);

await _storage.UploadStreamAsync("{YOUR_FILE_NAME}", stream);
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (12)

Showing the top 5 NuGet packages that depend on ManagedCode.Storage.Core:

Package Downloads
ManagedCode.Storage.Azure

Storage for Azure

ManagedCode.Storage.AspNetExtensions

Extensions for ASP.NET for Storage

ManagedCode.Storage.Aws

Storage for AWS

ManagedCode.Storage.FileSystem

Storage for FileSystem

ManagedCode.Storage.Gcp

Storage for Google Cloud Storage

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.1.21 771 7/31/2024
2.1.20 476 7/13/2024
2.1.19 288 6/14/2024
2.1.18 275 6/13/2024
2.1.17 165 6/12/2024
2.1.16 280 6/2/2024
2.1.15-alpha 550 5/22/2023
2.1.14 4,091 5/21/2023
2.1.13 6,547 12/20/2022
2.1.11 2,280 10/18/2022
2.1.10 1,201 10/18/2022
2.1.9 1,161 10/18/2022
2.1.8 1,171 10/18/2022
2.1.7 1,174 10/18/2022
2.1.6 1,196 10/18/2022
2.1.5 1,162 10/17/2022
2.1.4 1,200 10/17/2022
2.1.3 1,207 10/17/2022
2.1.2 1,196 10/16/2022
2.1.1 1,222 10/16/2022
2.1.0 1,224 10/14/2022
2.0.18 2,018 10/14/2022
2.0.11 5,261 8/12/2022
2.0.10 1,892 8/12/2022
2.0.9 1,864 8/11/2022
2.0.8 1,948 8/10/2022
2.0.7 1,830 8/9/2022
2.0.6 1,816 8/9/2022
2.0.5 1,918 8/8/2022
2.0.4 1,918 7/27/2022
2.0.3 1,860 7/26/2022
2.0.2 1,868 7/25/2022
2.0.1 1,980 7/22/2022
2.0.0 1,857 7/22/2022
1.2.1 1,947 7/17/2022
1.2.0 4,935 4/19/2022
1.1.2 1,641 4/18/2022
1.1.1 2,117 4/7/2022
1.1.0 1,771 3/29/2022
1.0.0 1,699 3/23/2022
0.1.0 1,791 3/22/2022
0.0.1 1,719 3/21/2022