App-vNext / Polly

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. From version 6.0.1, Polly targets .NET Standard 1.1 and 2.0+.
https://www.thepollyproject.org
BSD 3-Clause "New" or "Revised" License
13.44k stars 1.23k forks source link

Use Polly with EF Core #889

Closed sameer-kumar closed 1 year ago

sameer-kumar commented 3 years ago

Summary: What are you wanting to achieve? I'm looking for inputs and hopefully some reference implementation to use Polly with EF Core 3.1. My AspNetCore application uses Azure SQL with EF and repository pattern. I want to use Polly with RetryAndWait policy for Azure SQL requests beginning with initial connection. I have read that EF Core 3.1 supports EnableRetryOnFailure execution strategy on DbContext. However, I want to see if I can use Polly instead to be consistent with other areas of my application like webApi calls.

What code or approach do you have so far?
I tried google but couldn't find anything. So not sure if I'm thinking on right lines or its completely absurd.

Any insights or feedback is appreciated. Thanks!

martincostello commented 1 year ago

@martintmk Maybe we should include a sample for this scenario for v8?

martintmk commented 1 year ago

My vote would be to put this in https://github.com/App-vNext/Polly-Samples

suntereo commented 1 year ago

I'm also very interested in finding a reference implementation for using Polly with EF Core. I've been looking to integrate a circuit breaker pattern in EF Core, specifically for handling SQL downtimes. I noticed @martincostello that you've added this to the Polly v8.0.0 milestone, which is 96% complete but still open. I'm eagerly awaiting this example. If anyone has a temporary solution or guide on how to manually handle SQL connections for circuit breaking, it would be greatly appreciated. Thanks everyone!

martintmk commented 1 year ago

You can check the #1425 pull request where I experimented on how to leverage Polly V8 with Entity Framework Core.

Ultimately it served only as an exercise as it is very library-specific to be in this repo.

However, you can take an inspiration from it.