Shared.Infra.Core 1.2.0

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

Shared.Infra.Core — Consul KV com cache (TTL)

Leitura sob demanda do Consul KV com cache em memória.
Sem updater, sem setters: ao chamar GetKeyAsync, lê do cache; se ausente/expirado, busca no Consul, salva com TTL e retorna.


Registro (DI)

// Startup/Program
services.AddConsulConfiguration(
    consulUrl: "http://consul:8500/v1/kv",         // precisa incluir /v1/kv
    consulToken: Environment.GetEnvironmentVariable("CONSUL_TOKEN"),
    cacheDuration: TimeSpan.FromMinutes(5)         // TTL do cache
);

Uso

var consul = provider.GetRequiredService<IConsulService>();

// Retorna string ou null (se chave não existir)
var valor = await consul.GetKeyAsync("meu/sistema/base-url", ct);

// Em chamadas subsequentes dentro do TTL, retorna do cache.
// Após expirar, reconsulta o Consul e renova o TTL.

Comportamento

  • TTL (Time To Live): define por quanto tempo o valor fica válido no cache (configurado via cacheDuration).
  • Erros:
    • Chave inexistente → null.
    • Falhas HTTP/transientes → tentativas com backoff; ao final, loga erro e retorna null.
  • Thread-safe: usa IMemoryCache (concorrente) para armazenar as chaves.

O que foi removido

  • Atualizações em background (Hosted Service / updater).
  • “Setters”/normalizers e métodos auxiliares (JSON, invalidate, TTL dinâmico).

Requisitos

  • .NET com Microsoft.Extensions.Caching.Memory e IHttpClientFactory.
  • consulUrl apontando para o endpoint KV (ex.: http://host:8500/v1/kv).
  • (Opcional) CONSUL_TOKEN para Consul protegido por ACL.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.3.3 205 12/12/2025
1.3.2 201 12/12/2025
1.3.1 496 12/11/2025
1.3.0 266 12/3/2025
1.2.1 423 11/13/2025
1.2.0 358 11/13/2025
1.1.5 324 11/12/2025
1.1.4 324 11/12/2025
1.1.3 347 11/12/2025
1.1.2 356 11/11/2025
1.1.1 359 11/10/2025
1.1.0 204 11/7/2025
1.0.9 293 11/5/2025
1.0.8 286 11/3/2025
1.0.7 301 10/30/2025
1.0.6 271 10/29/2025
1.0.5 251 10/27/2025
1.0.4 227 10/24/2025
1.0.3 228 10/23/2025
1.0.2 247 10/23/2025
Loading failed