CH.Native.DependencyInjection 1.0.1-prerelease.15

This is a prerelease version of CH.Native.DependencyInjection.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CH.Native.DependencyInjection --version 1.0.1-prerelease.15
                    
NuGet\Install-Package CH.Native.DependencyInjection -Version 1.0.1-prerelease.15
                    
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="CH.Native.DependencyInjection" Version="1.0.1-prerelease.15" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CH.Native.DependencyInjection" Version="1.0.1-prerelease.15" />
                    
Directory.Packages.props
<PackageReference Include="CH.Native.DependencyInjection" />
                    
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 CH.Native.DependencyInjection --version 1.0.1-prerelease.15
                    
#r "nuget: CH.Native.DependencyInjection, 1.0.1-prerelease.15"
                    
#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 CH.Native.DependencyInjection@1.0.1-prerelease.15
                    
#: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=CH.Native.DependencyInjection&version=1.0.1-prerelease.15&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CH.Native.DependencyInjection&version=1.0.1-prerelease.15&prerelease
                    
Install as a Cake Tool

CH.Native.DependencyInjection

Microsoft.Extensions.DependencyInjection integration for CH.Native, the high-performance .NET client for ClickHouse using the native binary TCP protocol.

Registers ClickHouseDataSource as a singleton with optional keyed multi-database setups, IConfiguration binding, rotating-credential providers, and ASP.NET health checks.

Install

dotnet add package CH.Native.DependencyInjection

Usage

Connection string

builder.Services.AddClickHouse("Host=localhost;Database=default;Username=default");

Fluent builder

builder.Services.AddClickHouse(b => b
    .WithHost("clickhouse.internal")
    .WithDatabase("analytics")
    .WithCompression(true)
    .WithCompressionMethod(CompressionMethod.LZ4));

From IConfiguration

// appsettings.json
{
  "ClickHouse": {
    "Host": "clickhouse.internal",
    "Database": "analytics",
    "Username": "reader",
    "Pool": {
      "MaxPoolSize": 64,
      "PrewarmOnStart": true
    }
  }
}
builder.Services.AddClickHouse(builder.Configuration.GetSection("ClickHouse"));

Resolve and use

ClickHouseDataSource is a singleton; open a connection per unit of work. The connection returns to the pool on DisposeAsync.

public class EventsController(ClickHouseDataSource dataSource) : ControllerBase
{
    [HttpGet]
    public async IAsyncEnumerable<Event> GetEvents()
    {
        await using var conn = await dataSource.OpenConnectionAsync();
        await foreach (var row in conn.QueryAsync<Event>("SELECT * FROM events LIMIT 1000"))
            yield return row;
    }
}

Multiple databases (keyed)

builder.Services.AddClickHouse("analytics", analyticsConnString);
builder.Services.AddClickHouse("logs", logsConnString);

public class Reporter([FromKeyedServices("analytics")] ClickHouseDataSource ds) { }

Rotating credentials

Plug in providers for short-lived credentials (JWT, SSH key, mTLS cert, password). Each new physical connection re-resolves the credential.

builder.Services
    .AddClickHouse("Host=clickhouse.internal;Database=analytics")
    .WithJwtProvider<MyJwtProvider>();

public sealed class MyJwtProvider(IAccessTokenService tokens) : IClickHouseJwtProvider
{
    public ValueTask<string> GetTokenAsync(CancellationToken ct) => tokens.GetClickHouseTokenAsync(ct);
}

Equivalent interfaces exist for password (IClickHousePasswordProvider), SSH key (IClickHouseSshKeyProvider), and mTLS client certificate (IClickHouseCertificateProvider).

Health checks

builder.Services.AddHealthChecks()
    .AddClickHouse(name: "clickhouse");

License

MIT

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  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 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.1.2-prerelease.33 46 5/30/2026
1.1.2-prerelease.32 57 5/30/2026
1.1.2-prerelease.31 56 5/20/2026
1.1.2-prerelease.30 51 5/18/2026
1.1.2-prerelease.29 53 5/17/2026
1.1.2-prerelease.28 56 5/17/2026
1.1.2-prerelease.27 49 5/17/2026
1.1.2-prerelease.26 55 5/15/2026
1.1.1 103 5/9/2026
1.1.1-prerelease.25 55 5/9/2026
1.1.1-prerelease.24 73 5/8/2026
1.1.1-prerelease.23 54 5/7/2026
1.1.0 94 5/6/2026
1.1.0-prerelease.22 43 5/6/2026
1.0.1-prerelease.21 49 5/6/2026
1.0.1-prerelease.20 44 5/6/2026
1.0.1-prerelease.19 46 5/5/2026
1.0.1-prerelease.18 57 5/4/2026
1.0.1-prerelease.17 55 5/2/2026
1.0.1-prerelease.15 61 4/26/2026
Loading failed