Extend API around AddStandardResilienceHandler, so it provides access to IServiceProvider. #4767
Answered
by
StasPerekrestov
StasPerekrestov
asked this question in
Q&A
-
The public static IHttpClientBuilder AddPolicyHandler(
this IHttpClientBuilder builder,
Func<IServiceProvider, HttpRequestMessage, IAsyncPolicy<HttpResponseMessage>> policySelector)
{
//......
} I've been thinking, wouldn't it be helpful to extend the new resilience API, so it'll be possible to do something like the following services.AddHttpClient(...)
.AddStandardResilienceHandler(options => {
options.Retry.OnRetry = onRetryArguments =>
{
onRetryArguments.Context.Properties.TryGetValue<IServiceProvider>("somekey", out IServiceProvider sp);
var logger = sp.GetRequiredService<ILogger<...>>();
logger.Trace("Retry attempt {AttemptNumber} to {Url}", onRetryArguments.AttemptNumber, url);
return ValueTask.CompletedTask;
};
}); Thank you. |
Beta Was this translation helpful? Give feedback.
Answered by
StasPerekrestov
Nov 29, 2023
Replies: 1 comment
-
It looks like there is a workaround: services
.AddHttpClient("dummy")
.AddStandardResilienceHandler()
.Configure((options, serviceProvider) =>
{
// configure options here
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
StasPerekrestov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like there is a workaround: