diff --git a/src/Ocelot/DependencyInjection/OcelotBuilder.cs b/src/Ocelot/DependencyInjection/OcelotBuilder.cs index 3784e0c299..a071175832 100644 --- a/src/Ocelot/DependencyInjection/OcelotBuilder.cs +++ b/src/Ocelot/DependencyInjection/OcelotBuilder.cs @@ -53,10 +53,7 @@ public OcelotBuilder(IServiceCollection services, IConfiguration configurationRo Configuration = configurationRoot; Services = services; Services.Configure(configurationRoot); - Services.TryAddSingleton( - sp => sp - .GetRequiredService>() - .Value.GlobalConfiguration); + Services.Configure(configurationRoot.GetSection("GlobalConfiguration")); Services.TryAddSingleton(); Services.TryAddSingleton(); diff --git a/src/Ocelot/Requester/MessageInvokerPool.cs b/src/Ocelot/Requester/MessageInvokerPool.cs index 2dc152bd68..c02839ed39 100644 --- a/src/Ocelot/Requester/MessageInvokerPool.cs +++ b/src/Ocelot/Requester/MessageInvokerPool.cs @@ -1,4 +1,5 @@ -using Ocelot.Configuration; +using Microsoft.Extensions.Options; +using Ocelot.Configuration; using Ocelot.Configuration.File; using Ocelot.Logging; using System.Net.Security; @@ -10,11 +11,12 @@ public class MessageInvokerPool : IMessageInvokerPool private readonly ConcurrentDictionary> _handlersPool; private readonly IDelegatingHandlerHandlerFactory _handlerFactory; private readonly IOcelotLogger _logger; + private readonly FileGlobalConfiguration _global; public MessageInvokerPool( IDelegatingHandlerHandlerFactory handlerFactory, IOcelotLoggerFactory loggerFactory, - FileGlobalConfiguration fileGlobalConfigure) + IOptions global) { _handlerFactory = handlerFactory ?? throw new ArgumentNullException(nameof(handlerFactory)); _handlersPool = new ConcurrentDictionary>(); @@ -22,7 +24,8 @@ public MessageInvokerPool( ArgumentNullException.ThrowIfNull(loggerFactory); _logger = loggerFactory.CreateLogger(); - RequestTimeoutSeconds = fileGlobalConfigure.RequestTimeoutSeconds ?? 0; + _global = global.Value; + _requestTimeoutSeconds = _global.RequestTimeoutSeconds; } public HttpMessageInvoker Get(DownstreamRoute downstreamRoute) @@ -40,11 +43,11 @@ public HttpMessageInvoker Get(DownstreamRoute downstreamRoute) public const int DefaultRequestTimeoutSeconds = 90; - private int _requestTimeoutSeconds; + private int? _requestTimeoutSeconds; public int RequestTimeoutSeconds { - get => _requestTimeoutSeconds > 0 ? _requestTimeoutSeconds : DefaultRequestTimeoutSeconds; + get => _requestTimeoutSeconds ?? _global?.RequestTimeoutSeconds ?? DefaultRequestTimeoutSeconds; set => _requestTimeoutSeconds = value > 0 ? value : DefaultRequestTimeoutSeconds; }