diff --git a/src/Winton.Extensions.Configuration.Consul/ConsulConfigurationProvider.cs b/src/Winton.Extensions.Configuration.Consul/ConsulConfigurationProvider.cs index 6b11353..9fa3dfb 100644 --- a/src/Winton.Extensions.Configuration.Consul/ConsulConfigurationProvider.cs +++ b/src/Winton.Extensions.Configuration.Consul/ConsulConfigurationProvider.cs @@ -82,7 +82,7 @@ private async Task DoLoad(CancellationToken cancellationToken) if (result.HasValue()) { - SetData(result); + Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig); } else if (!_source.Optional) { @@ -134,9 +134,9 @@ private async Task PollingLoop(CancellationToken cancellationToken) { var result = await GetKvPairs(true, cancellationToken).ConfigureAwait(false); - if (result.HasValue() && result.LastIndex > _lastIndex) + if (result.LastIndex > _lastIndex) { - SetData(result); + Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig); OnReload(); } @@ -154,11 +154,6 @@ private async Task PollingLoop(CancellationToken cancellationToken) } } - private void SetData(QueryResult result) - { - Data = result.ToConfigDictionary(_source.ConvertConsulKVPairToConfig); - } - private void SetLastIndex(QueryResult result) { _lastIndex = result.LastIndex == 0 diff --git a/src/Winton.Extensions.Configuration.Consul/Extensions/KVPairQueryResultExtensions.cs b/src/Winton.Extensions.Configuration.Consul/Extensions/KVPairQueryResultExtensions.cs index c95d69a..707f6f1 100644 --- a/src/Winton.Extensions.Configuration.Consul/Extensions/KVPairQueryResultExtensions.cs +++ b/src/Winton.Extensions.Configuration.Consul/Extensions/KVPairQueryResultExtensions.cs @@ -6,13 +6,12 @@ using System.Linq; using System.Net; using Consul; -using Winton.Extensions.Configuration.Consul.Parsers; namespace Winton.Extensions.Configuration.Consul.Extensions { internal static class KVPairQueryResultExtensions { - internal static bool HasValue(this QueryResult result) + internal static bool HasValue(this QueryResult? result) { return result != null && result.StatusCode != HttpStatusCode.NotFound @@ -24,7 +23,7 @@ internal static Dictionary ToConfigDictionary( this QueryResult result, Func>> convertConsulKVPairToConfig) { - return (result.Response ?? new KVPair[0]) + return (result.Response ?? Array.Empty()) .Where(kvp => kvp.HasValue()) .SelectMany(convertConsulKVPairToConfig) .ToDictionary(kvp => kvp.Key, kvp => kvp.Value, StringComparer.OrdinalIgnoreCase);