SharpConnector 4.0.1

dotnet add package SharpConnector --version 4.0.1
                    
NuGet\Install-Package SharpConnector -Version 4.0.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="SharpConnector" Version="4.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SharpConnector" Version="4.0.1" />
                    
Directory.Packages.props
<PackageReference Include="SharpConnector" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SharpConnector --version 4.0.1
                    
#r "nuget: SharpConnector, 4.0.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.
#:package SharpConnector@4.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SharpConnector&version=4.0.1
                    
Install as a Cake Addin
#tool nuget:?package=SharpConnector&version=4.0.1
                    
Install as a Cake Tool

SharpConnector

License: MIT Nuget NuGet Downloads issues - dotnet-design-patterns Build stars - dotnet-design-patterns

<img src="https://github.com/engineering87/SharpConnector/blob/main/sharpconnector_logo.jpg" width="300">

SharpConnector is a .NET library designed to streamline integration with NoSQL databases. It provides a unified interface that simplifies database operations, eliminating the need to develop custom logic for each specific database connector. Since each NoSQL database has its own unique characteristics, such as being document-oriented or key-value-based, SharpConnector abstracts these differences, providing a consistent and simplified access layer to accelerate development.

✅ Now targeting .NET 9.

Table of Contents

Features

  • A single, generic client API for CRUD across multiple NoSQL engines
  • Supported stores:
    • Key–value: Redis, EnyimMemcached, DynamoDb
    • Document: MongoDB, LiteDB, RavenDB, Couchbase
    • Multi-model: ArangoDB
  • Simple configuration via appsettings.json and DI-friendly
  • Sync and async operations (with CancellationToken support)
  • Easy to extend: implement IOperations<T> for new connectors

Installation

You can install the library via the NuGet package manager with the following command:

dotnet add package SharpConnector

How it works

SharpConnector offers a unified interface for performing CRUD operations on various types of NoSQL databases. While NoSQL databases often differ in their internal structures (e.g., key-value stores, document databases), this library abstracts these distinctions, enabling streamlined key-value-based CRUD operations. Through SharpConnector, you can use a consistent interface to perform Insert, Get, Delete, and Update operations across multiple NoSQL systems, currently supporting:

  • Redis (key-value)
  • MongoDB (key-value or document-oriented)
  • LiteDB (embedded document database)
  • EnyimMemcached (key-value)
  • RavenDB (document-oriented)
  • Couchbase (document-oriented)
  • DynamoDb (key-value or document-oriented)
  • ArangoDB (multi-model)

SharpConnector thus simplifies the development process, providing flexibility and compatibility across diverse NoSQL paradigms without the need to handle specific database implementations.

How to use it

To get started with SharpConnector, configure the connector instance type. Then, add the specif ConnectorConfig node within your appsettings.json file:

  • Redis

      {
        "ConnectorConfig": {
      	"Instance": "Redis",
      	"DatabaseNumber": 0,
      	"ConnectionString": "redisServer:6380,password=password,ssl=True,abortConnect=False"
        }
      }
    
  • MongoDb

      {
        "ConnectorConfig": {
      	"Instance": "MongoDb",
      	"DatabaseName": "test",
      	"CollectionName": "test",
      	"ConnectionString": "mongodb_connectionstring_here"
        }
      }
    
  • LiteDB

      {
        "ConnectorConfig": {
      	"Instance": "LiteDb",
      	"CollectionName": "test",
      	"ConnectionString": "LiteDbTest.db"
        }
      }
    
  • Memcached

      {
        "ConnectorConfig": {
      	"Instance": "Memcached",
      	"ConnectionString": "127.0.0.1:11211"
        }
      }
    
  • RavenDB

      {
        "ConnectorConfig": {
      	"Instance": "RavenDb",
      	"DatabaseName": "test",
      	"ConnectionString": "http://live-test.ravendb.net"
        }
      }
    
  • Couchbase

      {
        "ConnectorConfig": {
      	"Instance": "Couchbase",
      	"ConnectionString": "couchbase://localhost",
      	"Username": "Administrator",
      	"Password": "password",
      	"BucketName": "example_bucket",
        }
      }
    
  • DynamoDb

      {
        "ConnectorConfig": {
      	"Instance": "DynamoDb",
      	"AccessKey": "your-access-key-here",
      	"SecretKey": "your-secret-key-here",
      	"Region": "us-west-2",
      	"ServiceUrl": "https://dynamodb.us-west-2.amazonaws.com",
      	"UseHttp": false,
      	"TableName": "MyTableName"
        }
      }
    
  • ArangoDB

      {
      	"ConnectorConfig": {
      		"Instance": "ArangoDb",
      		"ConnectionString": "http://localhost:8529",
      		"Username": "username",
      		"Password": "password",
      		"CollectionName": "test"
      	}
      }
    

Once configured, create a new SharpConnector client, specifying the payload type (e.g., string):

SharpConnectorClient<string> client = new SharpConnectorClient<string>()

Alternatively, you can integrate SharpConnector client using dependency injection. Here how to register the SharpConnector service with a simple string payload type:

// Register the SharpConnector services with string payload type.
builder.Services.AddSharpConnectorServices<string>();

This setup provides flexibility in working with different payload types and makes SharpConnector easy to use within dependency injection configurations.

API Overview

The main entry point is the generic ISharpConnectorClient<T>:

  • T Get(string key)
  • Task<T> GetAsync(string key, CancellationToken ct = default)
  • IEnumerable<T> GetAll()
  • Task<IEnumerable<T>> GetAllAsync(CancellationToken ct = default)
  • bool Insert(string key, T value)
  • bool Insert(string key, T value, TimeSpan expiration)
  • Task<bool> InsertAsync(string key, T value, CancellationToken ct = default)
  • Task<bool> InsertAsync(string key, T value, TimeSpan expiration, CancellationToken ct = default)
  • bool InsertMany(Dictionary<string,T> values)
  • bool InsertMany(Dictionary<string,T> values, TimeSpan expiration)
  • Task<bool> InsertManyAsync(IEnumerable<T> values, CancellationToken ct = default)
  • bool Update(string key, T value)
  • Task<bool> UpdateAsync(string key, T value, CancellationToken ct = default)
  • bool Delete(string key)
  • Task<bool> DeleteAsync(string key, CancellationToken ct = default)
  • bool Exists(string key)
  • Task<bool> ExistsAsync(string key, CancellationToken ct = default)
  • IEnumerable<T> Query(Func<T,bool> filter)
  • Task<IEnumerable<T>> QueryAsync(Func<T,bool> filter, CancellationToken ct = default)

Contributing

Thanks for considering a contribution! Please fork, branch, and open a PR.

  • Add unit tests for new features or connectors
  • Keep third-party dependencies compatible with MIT and document their licenses
  • Useful links:

Extending

To add a new connector:

  • Implement IOperations<T> for your backend.
  • Provide a wrapper/access layer (connection management, collection/table handles).
  • Add configuration binding under ConnectorConfig.
  • Include unit tests.

License

SharpConnector source code is available under MIT License, see license in the source.

External References

The SharpConnector library relies on several third-party libraries to deliver advanced functionality. Each of these libraries operates under a specific license, which governs its usage. To ensure transparency and compliance, the libraries and their licenses are listed in this repository:

  • StackExchange.Redis, a General purpose redis client, see license here
  • MongoDB.Driver, the Official C# .NET Driver for MongoDB, see license here
  • LiteDB, a .NET NoSQL Document Store in a single data file, see license here
  • EnyimMemcached, a C# Memcached client, see license here
  • RavenDB, ACID Document Database, see license here
  • Couchbase, the official Couchbase SDK for .NET Core and Full Frameworks, see license here
  • DynamoDb, the official AWS SDK for .NET, see license here
  • ArangoDB, a consistent, comprehensive, minimal driver for ArangoDB, see license here

Each library is included to enhance the functionality of SharpConnector while adhering to its licensing terms.

Contact

Please contact at francesco.delre[at]protonmail.com for any details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.1 36 3/11/2026
4.0.0 166 8/22/2025
3.3.0 219 3/19/2025
3.2.0 181 11/11/2024
3.1.0 170 10/29/2024
3.0.0 227 2/10/2024
2.0.0 449 1/22/2023
1.0.3 441 1/22/2023
1.0.2 572 8/1/2021
1.0.1 541 4/2/2021
1.0.0 620 11/25/2020