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
<PackageReference Include="Soenneker.Cosmos.Client" Version="4.0.3673" />
<PackageVersion Include="Soenneker.Cosmos.Client" Version="4.0.3673" />
<PackageReference Include="Soenneker.Cosmos.Client" />
paket add Soenneker.Cosmos.Client --version 4.0.3673
#r "nuget: Soenneker.Cosmos.Client, 4.0.3673"
#:package Soenneker.Cosmos.Client@4.0.3673
#addin nuget:?package=Soenneker.Cosmos.Client&version=4.0.3673
#tool nuget:?package=Soenneker.Cosmos.Client&version=4.0.3673
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 | Versions 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. |
-
net10.0
- Soenneker.Cosmos.Serializer (>= 4.0.2701)
- Soenneker.Enums.DeployEnvironment (>= 4.0.235)
- Soenneker.Extensions.Configuration (>= 4.0.868)
- Soenneker.Utils.HttpClientCache (>= 4.0.2045)
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 |
Update dependency Soenneker.Cosmos.Serializer to 4.0.2701 (#4535)