Fast.IaaS
Public members, parameters, returns, and exceptions
Targets: netstandard2.1.
Contract and constraints
General-purpose utilities and extensions in Fast.IaaS. This package targets .NET Standard 2.1 and needs neither a web host nor dependency injection. RetryUtil counts retries after the first attempt; retryTimeout is measured in milliseconds. A non-positive retry count executes once. A null action throws ArgumentNullException. Exception filters use assignability, fallback runs after exhaustion or an unmatched exception, and finalThrow controls rethrowing. Pass cancellation to both the operation and retry utility. TreeBuildUtil changes child collections, treats missing parents as roots, sorts with GetSort(), and does not detect cycles. Cryptographic algorithm availability depends on the runtime and operating system.
Installation and examples
Install the package
dotnet add package Fast.IaaSExample 1
using Fast.IaaS;
string duration = TimeSpan.FromMinutes(1).ToDescription(); // 01分00秒
string displayPhone = MaskingUtil.MobileMasking("13800000000");Example 2
public static Task InvokeAsync(
Func<Task> action, int numRetries, int retryTimeout = 1000,
bool finalThrow = true, Type[] exceptionTypes = null,
Func<Exception, Task> fallbackPolicy = null,
Func<int, int, Task> retryAction = null,
CancellationToken cancellationToken = default);Example 3
using Fast.IaaS;
public sealed class RetryingReader
{
public async Task<string> ReadAsync(
Func<CancellationToken, Task<string>> read,
CancellationToken cancellationToken)
{
string result = "";
await RetryUtil.InvokeAsync(
async () => { result = await read(cancellationToken); },
numRetries: 2,
retryTimeout: 200,
finalThrow: true,
exceptionTypes: new[] { typeof(IOException) },
cancellationToken: cancellationToken);
return result;
}
}Web-host examples belong in a consumer project using Microsoft.NET.Sdk.Web and a supported .NET target. IaaS examples can be used in an ordinary class library. Registration precedes builder.Build(); configure middleware and endpoints before app.Run(). Samples retain their original code and comments. No host, external service, database operation or client generator was run, and these snippets have not been compiled in this update.
Source reference
Cancellation boundary in the source fix
The source now checks caller cancellation before retry/fallback handling as well as before attempts and during retry delays. Once detected, cancellation propagates even when finalThrow is false and does not invoke fallback. The operation itself must observe the same token. With numRetries <= 0, the existing direct-call path does not apply retry callbacks, fallback or finalThrow.
