EdwardHsu.CircuitBreaker.HookInjector 1.0.2

dotnet add package EdwardHsu.CircuitBreaker.HookInjector --version 1.0.2
NuGet\Install-Package EdwardHsu.CircuitBreaker.HookInjector -Version 1.0.2
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="EdwardHsu.CircuitBreaker.HookInjector" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EdwardHsu.CircuitBreaker.HookInjector --version 1.0.2
#r "nuget: EdwardHsu.CircuitBreaker.HookInjector, 1.0.2"
#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.
// Install EdwardHsu.CircuitBreaker.HookInjector as a Cake Addin
#addin nuget:?package=EdwardHsu.CircuitBreaker.HookInjector&version=1.0.2

// Install EdwardHsu.CircuitBreaker.HookInjector as a Cake Tool
#tool nuget:?package=EdwardHsu.CircuitBreaker.HookInjector&version=1.0.2

EdwardHsu.CircuitBreaker

Unit Test codecov NuGet Version NuGet Download Github license

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

  1. Create a Circuit Breaker.
var fuse = new ExecutionLimitFuse(5);
var breaker = new CircuitBreaker(fuse);
  1. 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
}
  1. Control the Circuit Breaker.
breaker.On(); // Turn on the circuit breaker
breaker.Off(); // Turn off the circuit breaker
  1. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.2 77 4/8/2024