DotNetExtras.Retry
1.0.1
dotnet add package DotNetExtras.Retry --version 1.0.1
NuGet\Install-Package DotNetExtras.Retry -Version 1.0.1
<PackageReference Include="DotNetExtras.Retry" Version="1.0.1" />
<PackageVersion Include="DotNetExtras.Retry" Version="1.0.1" />
<PackageReference Include="DotNetExtras.Retry" />
paket add DotNetExtras.Retry --version 1.0.1
#r "nuget: DotNetExtras.Retry, 1.0.1"
#:package DotNetExtras.Retry@1.0.1
#addin nuget:?package=DotNetExtras.Retry&version=1.0.1
#tool nuget:?package=DotNetExtras.Retry&version=1.0.1
DotNetExtras.Retry
DotNetExtras.Retry
is a .NET Core library that allows applications to recover from and retry failed operations. This library is similar to Polly, but it is much simpler because it only focuses only on three most common scenarios.
Use the DotNetExtras.Retry
library to:
- Retry an operation a specified number of times with an optional delay between attempts.
- Retry an operation for the specified period of time with an optional delay between attempts.
- Reload an object (configuration, settings, etc.) and retry an operation with the reloaded state (one or more times or for a period of time, with an optional delay between attempts).
The nice thing about the DotNetExtras.Retry
library is that it is extremely easy to integrate with the existing code.
Usage
The following example illustrates how to detect a failure that may be caused by an old configuration setting, reload the settings, and retry the operation.
using DotNetExtras.Retry;
...
// This class implements the Reload() method of the IReloadable interface,
// in which it reloads the configuration settings that could have changed.
ReloadableService service = new();
// If the operation throws a NotSupportedException,
// reload the service object and retry the operation one more time.
// The operation is expected to return an int value.
int result = Execute.WithRetry<NotSupportedException, int>(() =>
{
// BEGINNING OF THE CODE BLOCK THAT WILL BE RETRIED.
try
{
// Attempt to perform the operation.
return service.DoSomething();
}
// This is not the expected exception for the retry,
// but...
catch (InvalidOperationException ex)
{
// ...we can simulate the expected exception for an appropriate condition.
if (ex.Message.StartsWith("Unexpected"))
{
throw new NotSupportedException("Simulated exception triggering a reload.", ex);
}
// This will handle both the expected exception
// leading to a reload and retry (one retry attempt only),
// as well as an unhandled exception that will
// result in error.
throw;
}
// END OF THE CODE BLOCK THAT WILL BE RETRIED.
}, service);
// We are passing the same service object here because it is the one that
// implements the reload method, but it can be a different object.
// We use the defaults for the delay (no delay) and the maximum attempts (2).
You can find the complete example and other scenarios covered in the demo application.
Documentation
For complete documentation, usage details, and code samples, see:
Package
Install the latest version of the DotNetExtras.Retry
NuGet package from:
See also
Check out other DotNetExtras
libraries at:
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.Extensions.Logging.Abstractions (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Improved documentation, no functional changes.