CircuitBreakerSyntax
Fluent API for defining a Circuit Breaker Policy.
using Polly.CircuitBreaker;
using System;
namespace Polly
{
public static class CircuitBreakerSyntax
{
public static Policy CircuitBreaker(this PolicyBuilder policyBuilder, int exceptionsAllowedBeforeBreaking, TimeSpan durationOfBreak)
{
if (exceptionsAllowedBeforeBreaking <= 0)
throw new ArgumentOutOfRangeException("exceptionsAllowedBeforeBreaking", "Value must be greater than zero.");
CircuitBreakerState policyState = new CircuitBreakerState(exceptionsAllowedBeforeBreaking, durationOfBreak);
return new Policy(delegate(Action action) {
CircuitBreakerPolicy.Implementation(action, policyBuilder.ExceptionPredicates, policyState);
}, policyBuilder.ExceptionPredicates);
}
}
}