JonjubNet.Resilience
1.0.7
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package JonjubNet.Resilience --version 1.0.7
NuGet\Install-Package JonjubNet.Resilience -Version 1.0.7
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="JonjubNet.Resilience" Version="1.0.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JonjubNet.Resilience" Version="1.0.7" />
<PackageReference Include="JonjubNet.Resilience" />
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 JonjubNet.Resilience --version 1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: JonjubNet.Resilience, 1.0.7"
#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 JonjubNet.Resilience@1.0.7
#: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=JonjubNet.Resilience&version=1.0.7
#tool nuget:?package=JonjubNet.Resilience&version=1.0.7
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
JonjubNet.Resilience
Una biblioteca de resiliencia para aplicaciones .NET que implementa patrones como Circuit Breaker, Retry, Timeout, Bulkhead y Fallback usando Polly.
Características
- Circuit Breaker: Protege contra fallos en cascada
- Retry: Reintentos automáticos con diferentes estrategias de backoff
- Timeout: Control de tiempo de espera para operaciones
- Bulkhead: Aislamiento de recursos
- Fallback: Estrategias de respaldo cuando las operaciones fallan
- Configuración flexible: Configuración por servicio y operación
- Logging estructurado: Integración con sistemas de logging
Instalación
dotnet add package JonjubNet.Resilience
Uso Básico
1. Configuración en appsettings.json
{
"Resilience": {
"Enabled": true,
"ServiceName": "MiAplicacion",
"Environment": "Development",
"CircuitBreaker": {
"Enabled": true,
"FailureThreshold": 5,
"SamplingDurationSeconds": 30,
"MinimumThroughput": 2,
"DurationOfBreakSeconds": 60
},
"Retry": {
"Enabled": true,
"MaxRetryAttempts": 3,
"BaseDelayMilliseconds": 1000,
"MaxDelayMilliseconds": 30000,
"BackoffStrategy": "Exponential"
},
"Timeout": {
"Enabled": true,
"DefaultTimeoutSeconds": 30,
"DatabaseTimeoutSeconds": 15,
"ExternalApiTimeoutSeconds": 10
}
}
}
2. Registro en Program.cs
using JonjubNet.Resilience;
var builder = WebApplication.CreateBuilder(args);
// Agregar infraestructura de resiliencia
builder.Services.AddResilienceInfrastructure(builder.Configuration);
3. Uso en servicios
public class MiServicio
{
private readonly IResilienceService _resilienceService;
public MiServicio(IResilienceService resilienceService)
{
_resilienceService = resilienceService;
}
public async Task<string> ObtenerDatosAsync()
{
return await _resilienceService.ExecuteWithResilienceAsync(
async () =>
{
// Tu lógica de negocio aquí
var httpClient = new HttpClient();
var response = await httpClient.GetAsync("https://api.ejemplo.com/datos");
return await response.Content.ReadAsStringAsync();
},
"ObtenerDatos",
"ApiExterna"
);
}
public async Task<string> ObtenerDatosConFallbackAsync()
{
return await _resilienceService.ExecuteWithFallbackAsync(
async () =>
{
// Operación principal
var httpClient = new HttpClient();
var response = await httpClient.GetAsync("https://api.ejemplo.com/datos");
return await response.Content.ReadAsStringAsync();
},
async () =>
{
// Operación de fallback
return "Datos por defecto";
},
"ObtenerDatosConFallback",
"ApiExterna"
);
}
}
Configuración Avanzada
Configuración por Servicio
{
"Resilience": {
"Services": {
"Database": {
"Enabled": true,
"Retry": {
"MaxRetryAttempts": 5,
"BaseDelayMilliseconds": 500
},
"Timeout": {
"DefaultTimeoutSeconds": 10
}
},
"HttpClient": {
"Enabled": true,
"CircuitBreaker": {
"FailureThreshold": 3,
"DurationOfBreakSeconds": 30
}
}
}
}
}
Configuración Programática
builder.Services.AddResilienceInfrastructure(builder.Configuration, options =>
{
options.Enabled = true;
options.ServiceName = "MiAplicacion";
options.Retry.MaxRetryAttempts = 5;
options.CircuitBreaker.FailureThreshold = 3;
});
Patrones de Resiliencia
Circuit Breaker
- Propósito: Evita llamadas a servicios que están fallando
- Configuración:
FailureThreshold,SamplingDurationSeconds,DurationOfBreakSeconds
Retry
- Propósito: Reintenta operaciones que fallan temporalmente
- Estrategias: Exponential, Linear, Fixed
- Configuración:
MaxRetryAttempts,BaseDelayMilliseconds,BackoffStrategy
Timeout
- Propósito: Limita el tiempo de espera de las operaciones
- Configuración:
DefaultTimeoutSeconds,DatabaseTimeoutSeconds,ExternalApiTimeoutSeconds
Fallback
- Propósito: Proporciona respuestas alternativas cuando las operaciones fallan
- Configuración:
EnableCacheFallback,EnableDefaultResponseFallback
Logging
La biblioteca integra con sistemas de logging estructurado. Asegúrate de implementar IStructuredLoggingService en tu aplicación:
public class MiLoggingService : IStructuredLoggingService
{
private readonly ILogger<MiLoggingService> _logger;
public MiLoggingService(ILogger<MiLoggingService> logger)
{
_logger = logger;
}
public void LogInformation(string message, string operationName, string category, Dictionary<string, object>? context = null)
{
_logger.LogInformation("{Message} | Operation: {OperationName} | Category: {Category}",
message, operationName, category);
}
// Implementar otros métodos...
}
Licencia
MIT License - ver archivo LICENSE para más detalles.
| 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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Http (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Options (>= 8.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
- Polly (>= 8.2.0)
- Polly.Extensions.Http (>= 3.0.0)
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.0.13 | 135 | 1/21/2026 |
| 1.0.12 | 101 | 1/20/2026 |
| 1.0.11 | 217 | 10/20/2025 |
| 1.0.10 | 198 | 10/20/2025 |
| 1.0.9 | 193 | 10/20/2025 |
| 1.0.8 | 205 | 10/19/2025 |
| 1.0.7 | 201 | 10/19/2025 |
| 1.0.6 | 200 | 10/19/2025 |
| 1.0.5 | 201 | 10/19/2025 |
| 1.0.4 | 206 | 10/19/2025 |
| 1.0.3 | 201 | 10/19/2025 |
| 1.0.2 | 190 | 10/19/2025 |
| 1.0.1 | 209 | 10/19/2025 |
| 1.0.0 | 209 | 10/19/2025 |