Soenneker.Cosmos.Client 11.0.3848

Prefix Reserved
dotnet add package Soenneker.Cosmos.Client --version 11.0.3848
                    
NuGet\Install-Package Soenneker.Cosmos.Client -Version 11.0.3848
                    
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="11.0.3848" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Cosmos.Client" Version="11.0.3848" />
                    
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 11.0.3848
                    
#r "nuget: Soenneker.Cosmos.Client, 11.0.3848"
                    
#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@11.0.3848
                    
#: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=11.0.3848
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Cosmos.Client&version=11.0.3848
                    
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 net11.0 is compatible. 
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
11.0.3848 0 11/6/2026
11.0.3847 264 11/3/2026
11.0.3846 104 11/3/2026
11.0.3845 163 11/3/2026
11.0.3844 85 11/3/2026
11.0.3842 93 11/3/2026
11.0.3841 234 11/2/2026
11.0.3840 779 10/29/2026
11.0.3839 362 10/27/2026
11.0.3838 102 10/27/2026
11.0.3837 677 10/27/2026
11.0.3836 224 10/27/2026
11.0.3835 91 10/26/2026
11.0.3834 100 10/26/2026
11.0.3830 251 10/26/2026
11.0.3829 95 10/26/2026
11.0.3828 222 10/26/2026
11.0.3827 94 10/26/2026
11.0.3826 600 10/26/2026
11.0.3824 237 10/26/2026
Loading failed

Update dependency Soenneker.Cosmos.Serializer to 11.0.2790 (#4738)