Uniphar.Cosmos.Extensions
0.0.1
TTL not getting expected value (in seconds)
See the version list below for details.
dotnet add package Uniphar.Cosmos.Extensions --version 0.0.1
NuGet\Install-Package Uniphar.Cosmos.Extensions -Version 0.0.1
<PackageReference Include="Uniphar.Cosmos.Extensions" Version="0.0.1" />
<PackageVersion Include="Uniphar.Cosmos.Extensions" Version="0.0.1" />
<PackageReference Include="Uniphar.Cosmos.Extensions" />
paket add Uniphar.Cosmos.Extensions --version 0.0.1
#r "nuget: Uniphar.Cosmos.Extensions, 0.0.1"
#:package Uniphar.Cosmos.Extensions@0.0.1
#addin nuget:?package=Uniphar.Cosmos.Extensions&version=0.0.1
#tool nuget:?package=Uniphar.Cosmos.Extensions&version=0.0.1
cosmos-extensions
NuGet package repository for Cosmos Extensions
Purpose
This library is intended for provisioning Az Cosmos Database(s) and container(s).
Setup your project to use Cosmos Extension package
When using this NuGet package you need to setup a few things in your project
appsettings.json
Add this to appsettings.json
with the appropriate values needed in your solution.
"StoreOptions": {
"DatabaseName": "<name of database>",
"DatabaseThroughput": <provisioned database throughput in RUs>,
"Containers": [
{
"InstanceName": "<name of container>",
"PartitionKey": "<name of partition key>",
"ContainerThroughput": <provisioned database throughput in RUs>,
"DefaultTimeToLiveInSeconds" : <TimeSpan(days, hours, seconds>
},
//...more containers to be defined
]
}
NOTE: Worth noting on the settings.
DatabaseThroughput
: integer, if undefined (null) it will default to 400; it will provision database with auto scaling as Manual throughput has been dismissed.Containers:PartitionKey
: string, if undefined (null), it will default to partioning by/partition
Containers:ContainerThroughput
: integer, if undefined (null) it will default to 400DefaultTimeToLiveInSeconds
: TimeSpan defining for how long data sholuld be retained; if undefined (null) we implemenmt it to default to -1 (items don’t expire by default)
Program.cs
Add the following to Program.cs
- Add this to bind the above configuration section to class
StoreOptions
. That will ensure we can DI it into the where ever we need to make the call.
builder.Services.Configure<StoreOptions>(
builder.Configuration.GetSection(nameof(StoreOptions)));
- Register a singleton instance of
CosmosClient
(MS recommendation) by adding this line
builder.Services.AddSingleton(CosmosClientExtension.CreateCosmosClient(builder.Configuration["Cosmos:ConnectionString"]));
NOTE: Cosmos Client connestionstring is defined in KeyVault.
CosmosInitialiser.cs (or other file responsible of Cosmos Initialisation)
Whatever file responsible for initialising cosmos database and containers (called from StartupBackgroundService.cs
) has a method ExecuteAsync(CancellationToken stoppingToken)
.
That method can be simplified to this
public async Task ExecuteAsync(CancellationToken stoppingToken)
{
_logger.LogInformation("Creating Cosmos Database And Containers");
await _cosmosExtension.ExecuteAsync(stoppingToken);
}
Create extended class of StoreOptions
Some APIs may have additional logic that is specific to the solutions. You can then create a class extension that inherits from StoreOptions
.
This is particular valid for PIMS API. You would create something like this.
public class ExtendedStoreOptions : StoreOptions
{
/// <summary>
/// Disable the account processing check
/// </summary>
/// <remarks>
/// If set to true all account processing checks will return true
/// Used to disable routing of requests to legacy pims system
/// </remarks>
public bool DisableAccountCheck { get; set; } = false;
}
Your appsettings.json
would look like this then
"ExtendedStoreOptions": {
"DatabaseName": "<name of database>",
"DatabaseThroughput": <provisioned database throughput in RUs>,
"DisableAccountCheck": true, // < --- this is the extra field from the above example
"Containers": [
{
"InstanceName": "<name of container>",
"PartitionKey": "<name of partition key>",
"ContainerThroughput": <provisioned database throughput in RUs>,
"DefaultTimeToLiveInSeconds" : <TimeSpan(days, hours, seconds>
},
//...more containers to be defined
]
}
Your program.cs would then need to bind the config section like this
builder.Services.Configure<ExtendedStoreOptions>(
builder.Configuration.GetSection(nameof(ExtendedStoreOptions)));
Likewise you;ll need to update Store.cs
to reflect using ExtendedStoreOptions
instead.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.0
- Microsoft.ApplicationInsights (>= 2.22.0)
- Microsoft.Azure.Cosmos (>= 3.38.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated | |
---|---|---|---|
4.15.0 | 191 | 9/11/2025 | |
4.14.0 | 796 | 8/28/2025 | |
4.13.1 | 954 | 7/30/2025 | |
4.13.0 | 95 | 7/28/2025 | |
4.12.0 | 521 | 7/23/2025 | |
4.11.0 | 936 | 7/2/2025 | |
4.10.0 | 1,254 | 4/23/2025 | |
4.9.0 | 391 | 4/17/2025 | |
4.8.0 | 217 | 4/17/2025 | |
4.7.0 | 366 | 4/15/2025 | |
4.6.0 | 282 | 4/11/2025 | |
4.5.0 | 171 | 4/11/2025 | |
4.4.1 | 302 | 4/9/2025 | |
4.4.0 | 237 | 4/9/2025 | |
4.3.0 | 233 | 4/8/2025 | |
4.2.0 | 187 | 4/7/2025 | |
4.1.0 | 158 | 4/4/2025 | |
4.0.0 | 222 | 4/2/2025 | |
3.8.0 | 763 | 4/1/2025 | |
3.7.0 | 836 | 3/20/2025 | |
3.6.1 | 610 | 3/12/2025 | |
3.6.0 | 246 | 3/11/2025 | |
3.5.0 | 284 | 3/10/2025 | |
3.4.0 | 1,172 | 3/6/2025 | |
3.3.0 | 936 | 2/24/2025 | |
3.2.0 | 237 | 2/20/2025 | |
3.1.0 | 493 | 2/14/2025 | |
3.0.1 | 1,381 | 12/11/2024 | |
3.0.0 | 115 | 12/6/2024 | |
2.3.0 | 2,959 | 10/24/2024 | |
2.2.0 | 137 | 10/24/2024 | |
2.1.0 | 1,323 | 7/30/2024 | |
2.0.1 | 943 | 5/16/2024 | |
2.0.0 | 94 | 5/14/2024 | |
1.1.1 | 570 | 4/22/2024 | |
1.1.0 | 311 | 4/10/2024 | |
1.0.0 | 239 | 4/8/2024 | |
0.0.4 | 235 | 3/29/2024 | |
0.0.3 | 241 | 3/27/2024 | |
0.0.2 | 157 | 3/27/2024 | |
0.0.1 | 174 | 3/26/2024 |