Uniphar.Platform.Common
1.0.12
dotnet add package Uniphar.Platform.Common --version 1.0.12
NuGet\Install-Package Uniphar.Platform.Common -Version 1.0.12
<PackageReference Include="Uniphar.Platform.Common" Version="1.0.12" />
<PackageVersion Include="Uniphar.Platform.Common" Version="1.0.12" />
<PackageReference Include="Uniphar.Platform.Common" />
paket add Uniphar.Platform.Common --version 1.0.12
#r "nuget: Uniphar.Platform.Common, 1.0.12"
#:package Uniphar.Platform.Common@1.0.12
#addin nuget:?package=Uniphar.Platform.Common&version=1.0.12
#tool nuget:?package=Uniphar.Platform.Common&version=1.0.12
platform-dotnet-common
This repository contains common libraries and utilities for .NET applications used across various projects within the organization.
KV management
Uniphar uses 2 kv's per domain, to do app segregation you can use this:
builder.Configuration.AddUniKeyVault("frontgate", "platform", builder.Environment.EnvironmentName, creds); // eg dev
It will do 3 things, setup the keyvault, authenticated with the TokenCredential provided, grab both all common--- and frontgate--- prefixed keyvault, and transforms configs the same way as usual AddAzureKeyVault does.
By default every common--- secret is loaded. To load only the common secrets you need, use ExcludeCommon() followed by fluent adds:
builder.Configuration.AddUniKeyVault("frontgate", "platform", builder.Environment.EnvironmentName, creds, o => o
.ExcludeCommon()
.AddCommonCosmos($"uni-devops-{env}") // common---uni-devops-{env}-cosmos-access-key
.AddCommonPwPush("my-api") // common---my-api-pw-push-auth-token
.AddCommonSecret("some-other-secret")); // common---some-other-secret
Secrets prefixed with the app name (frontgate---) are always loaded. AddCommonSecret is the generic add (the common--- prefix is added for you); AddCommonCosmos and AddCommonPwPush are helpers on top of it.
For IntegrationTests:
builder
.Configuration
.AddIntegrationTestsUniKeyVault("frontgate", "platform", builder.Environment.EnvironmentName, creds); // eg dev
This additionally loads all secrets from the integration Key Vault.
During migration, apps still on the shared legacy vault (uni-devops-app-{env}-kv) can use AddUniOldKeyvault(app, domain, env, creds) / AddIntegrationTestOldUniKeyvault(app, domain, env, creds) (same signature as the new methods, to ease the move). They use the standard -- delimiter and reload every 24h. The optional configure argument is accepted for signature parity but ignored, as the legacy vault has no prefixes and is always loaded in full. Remove once migrated.
For integration tests, AddIntegrationTestsUniKeyVault honours configure for the default vault (e.g. ExcludeCommon()), while the integration vault is always loaded in full.
Locking across regions
Distributed locking allows for coordination between different regions/application instances to ensure that certain operations are performed in a mutually exclusive manner.
This is particularly useful - given Uniphar tech stack - to run dapr based applications in multiple regions
Internal application uses Cosmos document to record lock status and job assignments. Job is simply an id for the operation that is being performed and requires locking.
Locks are periodically renewed and assignments periodically refreshed to ensure that they remain valid and rebalanced. Configuration is provided via DistributedLockServiceOptions.
Usage
To instrument the locking in the app, service collection and service provider extension methods have been provided.
builder.Services.AddCosmosLockService("cosmos-connection-string");
Then as you build the app, you can initialize the lock service
await app.Services.InitializeDistributedLockAsync("region-designation", "cosmos-database-name", "cosmos-collection-name");
Once initialized, you can use the DistributedLockService to acquire and release locks. For example:
bool lockAcquired = await dls.AcquireJobLockAsync(context.JobId);
if (lockAcquired)
{
//lock acquired, proceed with job processing
}
else
{
// Failed to acquire the lease, another instance may be processing
}
| 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
- Azure.Extensions.AspNetCore.Configuration.Secrets (>= 1.5.2)
- Azure.Identity (>= 1.21.0)
- Microsoft.Azure.Cosmos (>= 3.63.3)
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.14)
- Microsoft.Extensions.DependencyInjection (>= 10.0.14)
- Microsoft.Extensions.Logging (>= 10.0.14)
- Newtonsoft.Json (>= 13.0.4)
- Nito.AsyncEx (>= 5.1.2)
- Polly (>= 8.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.