Soenneker.Cosmos.Container 4.0.2500

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

Provides cached Azure Cosmos DB container handles plus list and delete operations.

Install

dotnet add package Soenneker.Cosmos.Container

Configuration

{
  "Azure": {
    "Cosmos": {
      "Endpoint": "https://your-account.documents.azure.com:443/",
      "AccountKey": "your-account-key",
      "DatabaseName": "application",
      "EnsureContainerOnFirstUse": true
    }
  }
}

EnsureContainerOnFirstUse defaults to true. On the first Get for a container, the setup utility attempts to create it with partition key path /partitionKey before returning the SDK handle. Set it to false when infrastructure provisioning owns container creation or your containers use another partition key path.

Registration

using Soenneker.Cosmos.Container.Registrars;

services.AddCosmosContainerUtilAsSingleton();

The registration includes the client, database, and container-setup dependencies and intentionally uses a singleton lifetime.

Get a container

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

public sealed class OrderStore(ICosmosContainerUtil containers)
{
    public ValueTask<Container> Get(CancellationToken cancellationToken)
    {
        return containers.Get("orders", cancellationToken);
    }
}

Use the explicit overload for another account or database:

Container container = await containers.Get(
    endpoint,
    accountKey,
    databaseName,
    containerName,
    cancellationToken);

Handles are cached by endpoint, a SHA-256 identity of the account key, database name, and container name. A rotated account key therefore receives a handle backed by the correct client without putting the raw key into the cache key.

List and delete

IReadOnlyList<ContainerProperties> existing = await containers.GetAll(cancellationToken);
await containers.Delete("obsolete", cancellationToken);

GetAll follows every Cosmos feed page and buffers all ContainerProperties in a list. DeleteAll lists the database and then deletes each container sequentially.

Operational notes

  • Delete and DeleteAll permanently remove Cosmos resources and their data. Scope credentials narrowly and do not expose these methods directly to untrusted input.
  • Delete obtains the cached handle before issuing the service deletion, then evicts that handle after success. A failed service deletion remains cached and the exception propagates.
  • Do not dispose returned Container handles. The singleton utilities own the underlying clients and caches.
  • Account keys are credentials. Store them in a secret provider and keep them out of logs and source control.
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 (2)

Showing the top 2 NuGet packages that depend on Soenneker.Cosmos.Container:

Package Downloads
Soenneker.Cosmos.Repository

A data persistence abstraction layer for Cosmos DB

Soenneker.Cosmos.Suite

A concoction of Azure Cosmos utilities and libraries

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.2503 0 8/31/2026
4.0.2502 10 8/30/2026
4.0.2501 118 8/30/2026
4.0.2500 44 8/30/2026
4.0.2499 44 8/30/2026
4.0.2498 104 8/30/2026
4.0.2497 47 8/30/2026
4.0.2496 78 8/29/2026
4.0.2495 38 8/29/2026
4.0.2494 328 8/27/2026
4.0.2493 175 8/26/2026
4.0.2492 130 8/26/2026
4.0.2491 392 8/22/2026
4.0.2490 210 8/22/2026
4.0.2489 295 8/21/2026
4.0.2488 581 8/19/2026
4.0.2487 256 8/18/2026
4.0.2486 250 8/18/2026
4.0.2485 421 8/14/2026
4.0.2484 184 8/13/2026
Loading failed

Update dependency Soenneker.Cosmos.Container.Setup to 4.0.2414 (#3332)