From 94f0c3d2d3462cb4b254cc2d8215e4d7e32eb3b5 Mon Sep 17 00:00:00 2001 From: Todd Date: Fri, 3 Nov 2023 12:26:14 -0500 Subject: [PATCH] #770 rename ConfigureAll -> WithDefaults --- src/Flurl.Http/Configuration/FlurlClientCache.cs | 15 ++++++++------- test/Flurl.Test/Http/FlurlClientCacheTests.cs | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Flurl.Http/Configuration/FlurlClientCache.cs b/src/Flurl.Http/Configuration/FlurlClientCache.cs index 82354ce3..a6b74a64 100644 --- a/src/Flurl.Http/Configuration/FlurlClientCache.cs +++ b/src/Flurl.Http/Configuration/FlurlClientCache.cs @@ -34,11 +34,12 @@ public interface IFlurlClientCache IFlurlClient GetOrAdd(string name, string baseUrl = null, Action configure = null); /// - /// Configuration logic that gets executed for every new IFlurlClient added this case. Good place for things like default - /// settings. Executes before client-specific builder logic. + /// Adds initialization logic that gets executed for every new IFlurlClient added this cache. + /// Good place for things like default settings. Executes before client-specific builder logic. + /// Call at startup (or whenever the cache is first created); clients already cached will NOT have this logic applied. /// /// This IFlurlCache. - IFlurlClientCache ConfigureAll(Action configure); + IFlurlClientCache WithDefaults(Action configure); /// /// Removes a named client from this cache. @@ -80,7 +81,7 @@ public static IFlurlClientCache Add(this IFlurlClientCache cache, string name, s public class FlurlClientCache : IFlurlClientCache { private readonly ConcurrentDictionary> _clients = new(); - private readonly List> _configureAll = new(); + private readonly List> _defaultConfigs = new(); /// public IFlurlClientBuilder Add(string name, string baseUrl = null) { @@ -123,9 +124,9 @@ Lazy Create() { } /// - public IFlurlClientCache ConfigureAll(Action configure) { + public IFlurlClientCache WithDefaults(Action configure) { if (configure != null) - _configureAll.Add(configure); + _defaultConfigs.Add(configure); return this; } @@ -146,7 +147,7 @@ public IFlurlClientCache Clear() { private IFlurlClientBuilder CreateBuilder(string baseUrl) { var builder = new FlurlClientBuilder(baseUrl); - foreach (var config in _configureAll) + foreach (var config in _defaultConfigs) config(builder); return builder; } diff --git a/test/Flurl.Test/Http/FlurlClientCacheTests.cs b/test/Flurl.Test/Http/FlurlClientCacheTests.cs index 2ffaad23..17494d6e 100644 --- a/test/Flurl.Test/Http/FlurlClientCacheTests.cs +++ b/test/Flurl.Test/Http/FlurlClientCacheTests.cs @@ -62,16 +62,16 @@ public void cannot_add_same_name_twice() { } [Test] - public void can_configure_all() { + public void can_configure_defaults() { var cache = new FlurlClientCache() - .ConfigureAll(b => b.WithSettings(s => s.Timeout = TimeSpan.FromSeconds(123))); + .WithDefaults(b => b.Settings.Timeout = TimeSpan.FromSeconds(123)); var cli1 = cache.GetOrAdd("foo"); cache.Add("bar").WithSettings(s => { s.Timeout = TimeSpan.FromSeconds(456); }); - cache.ConfigureAll(b => b.WithSettings(s => { + cache.WithDefaults(b => b.WithSettings(s => { s.Timeout = TimeSpan.FromSeconds(789); }));