EdwardHsu.CircuitBreaker
1.0.2
dotnet add package EdwardHsu.CircuitBreaker --version 1.0.2
NuGet\Install-Package EdwardHsu.CircuitBreaker -Version 1.0.2
<PackageReference Include="EdwardHsu.CircuitBreaker" Version="1.0.2" />
paket add EdwardHsu.CircuitBreaker --version 1.0.2
#r "nuget: EdwardHsu.CircuitBreaker, 1.0.2"
// Install EdwardHsu.CircuitBreaker as a Cake Addin #addin nuget:?package=EdwardHsu.CircuitBreaker&version=1.0.2 // Install EdwardHsu.CircuitBreaker as a Cake Tool #tool nuget:?package=EdwardHsu.CircuitBreaker&version=1.0.2
EdwardHsu.CircuitBreaker
CircuitBreaker is a .NET library that provides a circuit breaker pattern implementation for methods. It is designed to prevent a method from being executed too frequently or too intensively, which can lead to resource exhaustion or other issues.
Features
- Circuit Breaker: The CircuitBreaker class represents the circuit breaker and provides methods to control its state (on, tripped off, and off).
- Fuse: The IFuse interface defines the triggering conditions of the circuit breaker. The library provides two implementations:
- ExecutionLimitFuse: Trips the circuit breaker when the number of executions exceeds a specified limit.
- TimeSlidingWindowLimitFuse: Trips the circuit breaker when the number of executions within a specified time window exceeds a limit.
- Injection: The CircuitBreakerHookInjector class allows you to inject the circuit breaker into existing methods without modifying the code.
Installation
#main package
dotnet add package EdwardHsu.CircuitBreaker
#hook injector package
dotnet add package EdwardHsu.CircuitBreaker.HookInjector
Usage
- Create a Circuit Breaker.
var fuse = new ExecutionLimitFuse(5);
var breaker = new CircuitBreaker(fuse);
- Execute a Method through the Circuit Breaker.
try
{
breaker.Execute(new object[] { arg1, arg2 }); // Arguments can be passed to Fuse, which can determine whether to trigger based on these parameters.
}
catch (InvalidOperationException)
{
// Circuit breaker is tripped off
}
- Control the Circuit Breaker.
breaker.On(); // Turn on the circuit breaker
breaker.Off(); // Turn off the circuit breaker
- Inject the Circuit Breaker into an Existing Method.
breaker.Inject(() => myInstance.MyMethod(arg));
breaker.Inject(() => MyClass.MyStaticMethod(arg));
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net6.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on EdwardHsu.CircuitBreaker:
Package | Downloads |
---|---|
EdwardHsu.CircuitBreaker.HookInjector
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.2 | 157 | 4/8/2024 |