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

How to wire up Polly by Autofac #637

Closed Arash-Sabet closed 5 years ago

Arash-Sabet commented 5 years ago

Summary: What are you wanting to achieve?


I'd like to wire up Polly by Autofac. Are there any samples or guidelines to tell us how?

What code or approach do you have so far?


None.

reisenberger commented 5 years ago

@Arash-Sabet There are no Autofac samples. However, using any DI with Polly is fairly simple: a typical strategy is to register an IPolicyRegistry<string> with the DI container and have the container inject IPolicyRegistry<string> into components which need it. Within the component, retrieve the policy you require from the registry.

If on the other hand your question concerns Polly with HttpClientFactory, then this is less straightforward: HttpClientFactory is fairly tightly coupled to Microsoft.Extensions.DependencyInjection. See these two threads for deeper discussion and suggestions of possible workrounds: https://github.com/aspnet/HttpClientFactory/issues/148 ; https://github.com/aspnet/Extensions/issues/1345

Anybody from the community who has Autofac samples, please feel free to chip in!

reisenberger commented 5 years ago

Closing due to lack of further comment