Soenneker.Cosmos.Client 4.0.3673

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

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Cosmos.Client

Creates, caches, and disposes Azure Cosmos DB SDK clients with shared HTTP transport and Soenneker's System.Text.Json serializer.

Install

dotnet add package Soenneker.Cosmos.Client

Configuration

{
  "Environment": "Production",
  "Azure": {
    "Cosmos": {
      "Endpoint": "https://your-account.documents.azure.com:443/",
      "AccountKey": "your-account-key",
      "ConnectionMode": "Direct",
      "AllowBulkExecution": false,
      "AllowInsecureServerCertificate": false
    }
  }
}

ConnectionMode accepts Direct or Gateway and defaults to Direct when omitted. AllowBulkExecution is passed to CosmosClientOptions.

AllowInsecureServerCertificate defaults to false. It is accepted only when Environment is Local or Test and is intended solely for a local Cosmos emulator with an untrusted development certificate. Never enable it against a remote endpoint.

Registration

using Soenneker.Cosmos.Client.Registrars;
using Microsoft.Extensions.DependencyInjection;

var services = new ServiceCollection();
services.AddCosmosClientUtilAsSingleton();

The registrar intentionally exposes only a singleton lifetime because the Cosmos SDK client is designed for long-lived reuse.

Usage

using Microsoft.Azure.Cosmos;
using Soenneker.Cosmos.Client.Abstract;

public sealed class OrdersDatabase(ICosmosClientUtil clientUtil)
{
    public async ValueTask<Database> Get(CancellationToken cancellationToken)
    {
        CosmosClient client = await clientUtil.Get(cancellationToken);
        return client.GetDatabase("orders");
    }
}

For another account, use the explicit overload:

CosmosClient client = await clientUtil.Get(endpoint, accountKey, cancellationToken);

Clients are cached by endpoint and a SHA-256 identity of the account key. Calling the overload with a rotated key creates a separate client without storing the raw key in the cache key. HTTP transports are reused per endpoint within the utility instance.

Practical notes

  • Do not dispose a returned CosmosClient; the utility owns all clients it returns. Dependency injection disposes the utility at application shutdown.
  • Client creation is lazy. Configuration and SDK options are captured when a client is first requested.
  • The utility no longer modifies Cosmos SDK global trace listeners. Configure diagnostic logging through the application's logging and Cosmos SDK options.
  • Account keys are credentials. Keep them in a secret provider and redact authorization material and request diagnostics from logs.
  • Cancellation can stop lazy initialization; it does not cancel or dispose a client that has already been created.
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 (1)

Showing the top 1 NuGet packages that depend on Soenneker.Cosmos.Client:

Package Downloads
Soenneker.Cosmos.Database.Setup

A utility library for Azure Cosmos database setup operations

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.3673 0 8/31/2026
4.0.3671 0 8/31/2026
4.0.3670 0 8/31/2026
4.0.3669 0 8/30/2026
4.0.3668 0 8/30/2026
4.0.3666 0 8/30/2026
4.0.3664 40 8/30/2026
4.0.3662 40 8/30/2026
4.0.3661 36 8/30/2026
4.0.3659 37 8/29/2026
4.0.3657 79 8/29/2026
4.0.3656 37 8/29/2026
4.0.3655 38 8/29/2026
4.0.3654 36 8/29/2026
4.0.3652 497 8/26/2026
4.0.3651 205 8/26/2026
4.0.3650 61 8/26/2026
4.0.3649 156 8/26/2026
4.0.3648 73 8/26/2026
4.0.3647 72 8/25/2026
Loading failed

Update dependency Soenneker.Cosmos.Serializer to 4.0.2701 (#4535)