DbHub 1.0.0

dotnet add package DbHub --version 1.0.0
                    
NuGet\Install-Package DbHub -Version 1.0.0
                    
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="DbHub" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DbHub" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DbHub" />
                    
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 DbHub --version 1.0.0
                    
#r "nuget: DbHub, 1.0.0"
                    
#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 DbHub@1.0.0
                    
#: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=DbHub&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DbHub&version=1.0.0
                    
Install as a Cake Tool

DbHub

NuGet License: MIT

DbHub is a .NET 10 generic database execution engine built with Clean Architecture and Clean Code principles. It provides a unified API to connect to multiple database providers and execute queries, stored procedures, non-query commands, and scalar operations — with built-in Redis caching and MongoDB-based connection configuration.


Features

  • Multi-provider: SQL Server, MySQL, Oracle, MongoDB
  • Strategy pattern: Easily add new database providers
  • Redis caching: Connection strings are cached automatically
  • MongoDB config store: Connection and procedure configurations stored in MongoDB
  • Fully async: All operations are async/await with CancellationToken support
  • Strongly typed generics: Results mapped to your models
  • SOLID & Clean Architecture: Domain → Application → Infrastructure

Installation

dotnet add package DbHub

Quick Start

1. Register services

// Program.cs
builder.Services.AddDbHub(options =>
{
    options.MongoDbConnectionString = "mongodb://localhost:27017";
    options.MongoDbDatabase         = "DbHubConfig";
    options.RedisConnectionString   = "localhost:6379";
    options.CacheExpiry             = TimeSpan.FromHours(1);
});

2. Store a connection configuration in MongoDB

Insert a document into the ConnectionConfigs collection:

{
  "AppKey": "MyApp",
  "ConnectionType": 1,
  "DatabaseKey": "MainDb",
  "Server": "localhost",
  "Database": "MyDatabase",
  "User": "sa",
  "Password": "YourPassword",
  "Provider": "MSSQL",
  "Port": 0,
  "AdditionalSettings": {}
}

ConnectionType values: 1 = MSSQL, 2 = MYSQL, 3 = ORACLE, 4 = MONGODB

3. Execute operations

public class UserService(IDbHubService dbHub)
{
    public Task<IEnumerable<UserDto>> GetAllAsync(CancellationToken ct) =>
        dbHub.ExecuteQueryAsync<UserDto>(new DbHubRequest
        {
            AppKey         = "MyApp",
            ConnectionType = ConnectionType.MSSQL,
            DatabaseKey    = "MainDb",
            CommandText    = "SELECT Id, Name, Email FROM Users WHERE IsActive = @IsActive",
            Params         =
            [
                new DbHubParameter { Name = "IsActive", Value = true, Type = DbType.Boolean }
            ]
        }, ct);

    public Task<IEnumerable<UserDto>> GetByStoredProcedureAsync(CancellationToken ct) =>
        dbHub.ExecuteStoredProcedureAsync<UserDto>(new DbHubRequest
        {
            AppKey         = "MyApp",
            ConnectionType = ConnectionType.MSSQL,
            DatabaseKey    = "MainDb",
            ProcedureKey   = "GET_ACTIVE_USERS"
        }, ct);

    public Task<int> InsertAsync(string name, CancellationToken ct) =>
        dbHub.ExecuteNonQueryAsync(new DbHubRequest
        {
            AppKey         = "MyApp",
            ConnectionType = ConnectionType.MSSQL,
            DatabaseKey    = "MainDb",
            CommandText    = "INSERT INTO Users (Name) VALUES (@Name)",
            Params         = [new DbHubParameter { Name = "Name", Value = name }]
        }, ct);

    public Task<int?> CountAsync(CancellationToken ct) =>
        dbHub.ExecuteScalarAsync<int?>(new DbHubRequest
        {
            AppKey         = "MyApp",
            ConnectionType = ConnectionType.MSSQL,
            DatabaseKey    = "MainDb",
            CommandText    = "SELECT COUNT(*) FROM Users"
        }, ct);
}

MongoDB Provider

Operation Behavior
ExecuteQueryAsync<T> Finds documents. CommandText = collection name. Params = equality filters.
ExecuteStoredProcedureAsync<T> Runs aggregation pipeline. procedureName = collection. CommandText = JSON pipeline array.
ExecuteNonQueryAsync Deletes matching documents. CommandText = collection. Params = filter. Returns deleted count.
ExecuteScalarAsync<T> Counts matching documents. CommandText = collection. Params = filter.

Architecture

DbHub                ← Public NuGet entry point
DbHub.Infrastructure ← Providers, repositories, cache, DI
DbHub.Application    ← Interfaces, services, request models
DbHub.Domain         ← Entities, interfaces
DbHub.Shared         ← Enums, models, utilities
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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
1.0.0 114 3/11/2026