Skip to main content

John Evdemon

Using Polly Context

1 min read

Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.  The biggest challenge I've found with Polly is getting visibilty into the number of times you had to retry.  Luckily Polly allows us to pass in a Context (Dictionary) that we can populate with retry info. We can access the Context after our retry policy has completed to determine how many times we retried.

I've created a simple console app illustrating how you can use Polly Context to determine how many times your retry polcy was executed.

You can set up a Fiddler autoresponder rule to simulate transient service errors as follows: