diff --git a/src/Ocelot.Provider.Polly/PollyQoSProviderBase.cs b/src/Ocelot.Provider.Polly/PollyQoSProviderBase.cs index 24760c800..73a3f18f4 100644 --- a/src/Ocelot.Provider.Polly/PollyQoSProviderBase.cs +++ b/src/Ocelot.Provider.Polly/PollyQoSProviderBase.cs @@ -1,10 +1,29 @@ using Ocelot.Configuration; +using Ocelot.Configuration.File; using System.Net; namespace Ocelot.Provider.Polly; public abstract class PollyQoSProviderBase { + protected PollyQoSProviderBase(FileGlobalConfiguration global) + { + _global = global; + _requestTimeoutSeconds = _global.RequestTimeoutSeconds; + } + + protected readonly FileGlobalConfiguration _global; + + protected const int DefaultRequestTimeoutSeconds = 90; + + private int? _requestTimeoutSeconds; + + protected int RequestTimeoutSeconds + { + get => _requestTimeoutSeconds ?? _global?.RequestTimeoutSeconds ?? DefaultRequestTimeoutSeconds; + set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds; + } + protected static readonly HashSet ServerErrorCodes = new() { HttpStatusCode.InternalServerError, diff --git a/src/Ocelot.Provider.Polly/PollyQoSResiliencePipelineProvider.cs b/src/Ocelot.Provider.Polly/PollyQoSResiliencePipelineProvider.cs index 51fdf5e5a..2f9373d5a 100644 --- a/src/Ocelot.Provider.Polly/PollyQoSResiliencePipelineProvider.cs +++ b/src/Ocelot.Provider.Polly/PollyQoSResiliencePipelineProvider.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Options; using Ocelot.Configuration; using Ocelot.Configuration.File; using Ocelot.Logging; @@ -11,24 +12,16 @@ namespace Ocelot.Provider.Polly; /// /// Default provider for Polly V8 pipelines. /// -public class PollyQoSResiliencePipelineProvider : PollyQoSProviderBase, IPollyQoSResiliencePipelineProvider +public class PollyQoSResiliencePipelineProvider + : PollyQoSProviderBase, IPollyQoSResiliencePipelineProvider { private readonly ResiliencePipelineRegistry _resiliencePipelineRegistry; private readonly IOcelotLogger _logger; - - public const int DefaultRequestTimeoutSeconds = 90; - private int _requestTimeoutSeconds; - - public int RequestTimeoutSeconds - { - get => _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds; - set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds; - } public PollyQoSResiliencePipelineProvider( IOcelotLoggerFactory loggerFactory, ResiliencePipelineRegistry resiliencePipelineRegistry, - FileGlobalConfiguration fileGlobalConfigure) + IOptions global) : base(global.Value) { _resiliencePipelineRegistry = resiliencePipelineRegistry; _logger = loggerFactory.CreateLogger(); diff --git a/src/Ocelot.Provider.Polly/v7/PollyQoSProvider.cs b/src/Ocelot.Provider.Polly/v7/PollyQoSProvider.cs index 9d3801ce5..c349d37cf 100644 --- a/src/Ocelot.Provider.Polly/v7/PollyQoSProvider.cs +++ b/src/Ocelot.Provider.Polly/v7/PollyQoSProvider.cs @@ -1,4 +1,5 @@ -using Ocelot.Configuration; +using Microsoft.Extensions.Options; +using Ocelot.Configuration; using Ocelot.Configuration.File; using Ocelot.Logging; using Polly.CircuitBreaker; @@ -15,21 +16,12 @@ public class PollyQoSProvider : PollyQoSProviderBase, IPollyQoSProvider _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds; - set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds; - } - - public PollyQoSProvider(IOcelotLoggerFactory loggerFactory, FileGlobalConfiguration fileGlobalConfiguration) + public PollyQoSProvider( + IOcelotLoggerFactory loggerFactory, + IOptions global) : base(global.Value) { _logger = loggerFactory.CreateLogger(); - RequestTimeoutSeconds = fileGlobalConfiguration.RequestTimeoutSeconds ?? 0; } [Obsolete("Due to new v8 policy definition in Polly 8 (use GetResiliencePipeline in PollyQoSResiliencePipelineProvider)")]