An open API service indexing awesome lists of open source software.

https://github.com/RicoSuter/Namotion.Storage

.NET abstractions and implementations for storage services like blob storages, file systems or object storages.
https://github.com/RicoSuter/Namotion.Storage

Last synced: 6 months ago
JSON representation

.NET abstractions and implementations for storage services like blob storages, file systems or object storages.

Awesome Lists containing this project

README

          

# Namotion.Storage

Storage | [Messaging](https://github.com/RicoSuter/Namotion.Messaging) | [Reflection](https://github.com/RicoSuter/Namotion.Reflection)

[![Azure DevOps](https://img.shields.io/azure-devops/build/rsuter/9023bd0a-b641-4e30-9c0f-a7c15e1e080e/20/master.svg)](https://dev.azure.com/rsuter/Namotion/_build?definitionId=20)
[![Azure DevOps](https://img.shields.io/azure-devops/coverage/rsuter/9023bd0a-b641-4e30-9c0f-a7c15e1e080e/20/master.svg)](https://dev.azure.com/rsuter/Namotion/_build?definitionId=20)
[![Discord](https://img.shields.io/badge/Discord-join%20chat-1dce73.svg)](https://discord.gg/BxQNy25WF6)

The Namotion.Storage .NET libraries provide abstractions and implementations for storage services like blob storages, file systems or object storages.

By programming against a storage abstraction you enable the following scenarios:

- Build **multi-cloud capable applications** by being able to change storage technologies on demand.
- Quickly **switch to different storage technologies** to find the best technological fit for your applications.
- Implement behavior driven **integration tests which can run in-memory** or against different technologies for better debugging experiences or local execution.
- Provide **better local development experiences**, e.g. replace Azure Blob Storage with the local file system or an in-memory implementation.

## Usage

In your application root, create an `IBlobStorage` instance with an actual implementation package and retrieve a blob container:

```csharp
var storage = AzureBlobStorage.CreateFromConnectionString("MyConnectionString");
IBlobContainer container = storage.GetContainer("MyContainer");
IBlobContainer typedContainer = container.WithBlobType();

await typedContainer.WriteJsonAsync("MyPath", new Person { ... });
var person = await typedContainer.ReadJsonAsync("MyPath");
```

In your business service classes you should then only use the abstraction interfaces like `IBlobContainer` or `IObjectStorage`, etc.

## Core packages

### Namotion.Storage.Abstractions

[![Nuget](https://img.shields.io/nuget/v/Namotion.Storage.Abstractions.svg)](https://www.nuget.org/packages/Namotion.Storage.Abstractions/)
[![Apimundo](https://img.shields.io/badge/Namotion.Storage.Abstractions%20API-Apimundo-728199.svg)](https://apimundo.com/organizations/nuget-org/nuget-feeds/public/packages/Namotion.Storage.Abstractions/versions/latest?tab=types)

**Blobs**

Inject `IBlobStorage` or `IBlobContainer` but do not get a container from a blob storage in the consuming class (violates [SRP](http://software-pattern.org/single-responsibility-principle)).

- **IBlobStorage**: A blob storage where blobs are stored in a container and cannot be directly stored. Only `containerName/blobName` or `containerName/subDirectories/blobName` are allowed.
- **IBlobContainer\**
- **IBlobContainer**: A blob container where blobs can be directly stored or in a subdirectory. A container acts like a simple/basic virtual file system.
- `OpenWriteAsync`: Creates or overrides an existing blob
- `OpenAppendAsync`: Creates or appends to an existing blob
- `OpenReadAsync`
- `ExistsAsync`
- `GetAsync`
- `ListAsync`
- `DeleteAsync`: Deletes a blob
- **BlobElement**: Metadata and properties of a blob or container.

Internal:

- **IBlobReader**: Internal (do not use directly.)
- **IBlobWriter**: Internal (do not use directly.)

The idea behind the generic interfaces is to allow multiple instance registrations, read [Dependency Injection in .NET: A way to work around missing named registrations](https://blog.rsuter.com/dotnet-dependency-injection-way-to-work-around-missing-named-registrations/) for more information.

**Objects**

- **IObjectStorage\**
- `WriteAsync(id, value)`
- `ReadAsync(id)`
- `DeleteAsync(id)`

### Namotion.Storage.Json

[![Nuget](https://img.shields.io/nuget/v/Namotion.Storage.Json.svg)](https://www.nuget.org/packages/Namotion.Storage.Json/)
[![Apimundo](https://img.shields.io/badge/Namotion.Storage.Json%20API-Apimundo-728199.svg)](https://apimundo.com/organizations/nuget-org/nuget-feeds/public/packages/Namotion.Storage.Json/versions/latest?tab=types)

Extension methods:

- `WriteAsJson()`: Writes an object as JSON into a blob container/storage.
- `ReadAsJson()`: Reads an object as JSON from a blob container/storage.
- `CreateJsonObjectStorage()`: Creates an `IObjectStorage` for a given `IBlobContainer`. Usage: `var objectStorage = blobContainer.CreateJsonObjectStorage()`.

## Implementation packages

The following packages should only be used in the head project, i.e. directly in your application bootstrapping project where the dependency injection container is initialized.

### Namotion.Storage

[![Nuget](https://img.shields.io/nuget/v/Namotion.Storage.svg)](https://www.nuget.org/packages/Namotion.Storage/)
[![Apimundo](https://img.shields.io/badge/Namotion.Storage%20API-Apimundo-728199.svg)](https://apimundo.com/organizations/nuget-org/nuget-feeds/public/packages/Namotion.Storage/versions/latest?tab=types)

Implementations:

- FileSystemBlobStorage
- InMemoryBlobStorage

Extensions:

- `WithBlobType()`: Adds a blob type to an `IBlobStorage/IBlobContainer` and transforms it into a `IBlobStorage/IBlobContainer`.
- `Wrap()/Wrap()`: Adds an interceptor to the blob storage (`blobStorage.Wrap(s => new MyInterceptor(s))`). An interceptor can be implemented as a new class inheriting from the `BlobStorage` class and overriding some methods.

### Namotion.Storage.Azure.Storage.Blob

[![Nuget](https://img.shields.io/nuget/v/Namotion.Storage.Azure.Storage.Blob.svg)](https://www.nuget.org/packages/Namotion.Storage.Azure.Storage.Blob/)
[![Apimundo](https://img.shields.io/badge/Namotion.Storage.Azure.Storage.Blob%20API-Apimundo-728199.svg)](https://apimundo.com/organizations/nuget-org/nuget-feeds/public/packages/Namotion.Storage.Azure.Storage.Blob/versions/latest?tab=types)

Implementations:

- AzureBlobStorage

### Namotion.Storage.Ftp

[![Nuget](https://img.shields.io/nuget/v/Namotion.Storage.Ftp.svg)](https://www.nuget.org/packages/Namotion.Storage.Ftp.Blob/)
[![Apimundo](https://img.shields.io/badge/Namotion.Storage.Ftp%20API-Apimundo-728199.svg)](https://apimundo.com/organizations/nuget-org/nuget-feeds/public/packages/Namotion.Storage.Ftp/versions/latest?tab=types)

Implementations:

- FtpBlobStorage