<PackageReference Include="Polly.Core" Version="8.3.0" />

CircuitBreakerStateProvider

public sealed class CircuitBreakerStateProvider
Allows retrieval of the circuit breaker state.
using System; using System.Runtime.CompilerServices; namespace Polly.CircuitBreaker { public sealed class CircuitBreakerStateProvider { [System.Runtime.CompilerServices.Nullable(2)] private Func<CircuitState> _circuitStateProvider; internal bool IsInitialized => _circuitStateProvider != null; public CircuitState CircuitState => _circuitStateProvider?.Invoke() ?? CircuitState.Closed; [System.Runtime.CompilerServices.NullableContext(1)] internal void Initialize(Func<CircuitState> circuitStateProvider) { if (_circuitStateProvider != null) throw new InvalidOperationException("This instance of 'CircuitBreakerStateProvider' is already initialized and cannot be used in a different circuit-breaker strategy."); _circuitStateProvider = circuitStateProvider; } } }