CosmosKit 5.0.1
See the version list below for details.
dotnet add package CosmosKit --version 5.0.1
NuGet\Install-Package CosmosKit -Version 5.0.1
<PackageReference Include="CosmosKit" Version="5.0.1" />
<PackageVersion Include="CosmosKit" Version="5.0.1" />
<PackageReference Include="CosmosKit" />
paket add CosmosKit --version 5.0.1
#r "nuget: CosmosKit, 5.0.1"
#:package CosmosKit@5.0.1
#addin nuget:?package=CosmosKit&version=5.0.1
#tool nuget:?package=CosmosKit&version=5.0.1
CosmosKit
CosmosKit provides Repository and Unit of Work patterns on top of the Azure Cosmos DB SDK. It simplifies data access by encapsulating common operations and transactional batch logic.
Installation
Add a reference to the package (once published) or include the project in your solution.
<PackageReference Include="CosmosKit" Version="*" />
Configuration
- Register
CosmosClient
in your service container. - Call
AddCosmosKit
specifying the database id and your entity containers.
builder.Services.AddSingleton(new CosmosClient(connectionString));
builder.AddCosmosKit(
databaseId: "AppDb",
new []
{
new DependencyInjection.EntityContainer(typeof(Order), "orders", "TenantId"),
new DependencyInjection.EntityContainer(typeof(Customer), "customers", "TenantId")
});
Usage
Obtain an IUnitOfWork
from dependency injection and use repositories to perform operations. Use transactions when you need to group multiple operations within the same partition key.
public class OrderService
{
private readonly IUnitOfWork _uow;
public OrderService(IUnitOfWork uow)
{
_uow = uow;
}
public async Task CreateOrderAsync(Order order, CancellationToken ct)
{
var repo = _uow.GetRepository<Order>();
await repo.AddAsync(order, ct);
}
}
GetRepository
returns a repository proxy that automatically participates in transactions started on the unit of work.
Streaming Queries
IRepository
exposes StreamAsync
to asynchronously enumerate large query results without buffering:
await foreach(var order in repo.StreamAsync(o => o.Status == "new", ct))
{
// process order
}
License
This project is licensed under the MIT License.
Product | Versions 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 was computed. 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 was computed. 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. |
-
net8.0
- Microsoft.Azure.Cosmos (>= 3.51.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.5)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.