AddTransientHttpErrorPolicy 和 AddPolicyHandler 有什么区别?

What is the difference between AddTransientHttpErrorPolicy and AddPolicyHandler?

我想使用 Polly. I am using HttpClientFactory from ASP.NET Core 2.1. I found some guide on Polly GitHub wiki 应用弹性策略。这种策略配置有两种方式——使用 AddTransientHttpErrorPolicy 和 AddPolicyHandler,但不多做解释。它们之间有什么区别?

.AddTransientHttpErrorPolicy(...) 为您嵌入了要处理的 内容 的规范(网络故障、5xx 和 408 响应,如 in the wiki 所述)。您只需指定如何处理(例如重试、断路器)。

使用 .AddPolicyHandler(...),您可以自己指定整个策略:要处理什么 (.Handle<>(), .Or<>(), .OrResult<HttpResponseMessage()等)和如何处理(例如重试,断路器)。如图here in the Polly wiki.

除此之外,IHttpClientFactory 使用已配置策略的方式没有区别。