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.
$ dotnet add package EdwardHsu.CircuitBreakerCircuitBreaker 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.
#main package
dotnet add package EdwardHsu.CircuitBreaker
#hook injector package
dotnet add package EdwardHsu.CircuitBreaker.HookInjector
var fuse = new ExecutionLimitFuse(5);
var breaker = new CircuitBreaker(fuse);
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
}
breaker.On(); // Turn on the circuit breaker
breaker.Off(); // Turn off the circuit breaker
breaker.Inject(() => myInstance.MyMethod(arg));
breaker.Inject(() => MyClass.MyStaticMethod(arg));
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.
This project is licensed under the MIT License.