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+.

Home Page:https://www.thepollyproject.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature request]: Add TimeProvider argument to resilience extension methods

silkfire opened this issue · comments

Is your feature request related to a specific problem? Or an existing feature?

When creating a ResiliencePipelineBuilder, the consumer is offered to set a custom ITimeProvider by setting the TimeProvider property on the builder. This is not possible when using e.g. HTTP resilience extension methods like AddStandardResilienceHandler as the builder is created internally.

Describe the solution you'd like

It'd be useful if an overload was provided that allows the consumer of the extension methods to specify a ITimeProvider argument of their own choice, so as to increase flexibility for e.g. unit tests.

Additional context

No response

Could you clarify exactly which methods you want this added to?

If it's the AddStandardResilienceHandler() methods, they don't live in this repository but in dotnet/extensions.

The methods I was referring to were AddStandardResiliencePipeline and AddResiliencePipeline. I wasn't actually aware that they belonged to a different repository. Should I open an issue there instead?

I don't seem to be able to find AddStandardResiliencePipeline() in either repository with GitHub code search. AddStandardResilienceHandler() is in dotnt/extensions, where as AddResiliencePipeline() lives here.

public static IServiceCollection AddResiliencePipeline<TKey>(

@silkfire If TimeProvider is registered in the DI, the AddResiliencePipeline will automatically use and assign it:

if (serviceProvider.GetService<TimeProvider>() is { } timeProvider)

I don't seem to be able to find AddStandardResiliencePipeline() in either repository with GitHub code search. AddStandardResilienceHandler() is in dotnt/extensions, where as AddResiliencePipeline() lives here.

public static IServiceCollection AddResiliencePipeline<TKey>(

Apologies, it was late and I got the methods mixed up. The one I intended was AddStandardResilienceHandler().

@silkfire If TimeProvider is registered in the DI, the AddResiliencePipeline will automatically use and assign it:

if (serviceProvider.GetService<TimeProvider>() is { } timeProvider)

Interesting, I wasn't aware of that, this might actually be sufficient for my use case. Thank you.