11using System ;
22using System . Collections . Generic ;
3+ using Microsoft . Extensions . Configuration ;
34using Etcd . Microsoft . Extensions . Configuration . Client ;
45using Etcd . Microsoft . Extensions . Configuration . Watch ;
5- using Microsoft . Extensions . Configuration ;
66
77namespace Etcd . Microsoft . Extensions . Configuration ;
88
@@ -27,9 +27,6 @@ public EtcdConfigurationProvider(IEtcdKeyValueClient client, string? keyPrefix =
2727 _client = client ;
2828 _keyPrefix = keyPrefix ;
2929
30- if ( _keyPrefix != null )
31- _keyPrefix += ":" ;
32-
3330 _client . WatchCallback += OnWatchCallback ;
3431 }
3532
@@ -46,13 +43,21 @@ public EtcdConfigurationProvider(IEtcdKeyValueClient client, string? keyPrefix =
4643 /// <returns>
4744 /// True if key has a value, false otherwise.
4845 /// </returns>
49- public override bool TryGet ( string key , out string value ) => base . TryGet ( _keyPrefix + key , out value ) ;
46+ public override bool TryGet ( string key , out string value ) =>
47+ base . TryGet ( _keyPrefix == null
48+ ? key
49+ : _keyPrefix + ":" + key
50+ , out value ) ;
5051
5152 /// <summary>Returns the list of keys that this provider has.</summary>
5253 /// <param name="earlierKeys">The earlier keys that other providers contain.</param>
5354 /// <param name="parentPath">The path for the parent IConfiguration.</param>
5455 /// <returns>The list of keys for this provider.</returns>
55- public override IEnumerable < string > GetChildKeys ( IEnumerable < string > earlierKeys , string parentPath ) => base . GetChildKeys ( earlierKeys , _keyPrefix + parentPath ) ;
56+ public override IEnumerable < string > GetChildKeys ( IEnumerable < string > earlierKeys , string parentPath ) =>
57+ base . GetChildKeys ( earlierKeys ,
58+ _keyPrefix != null
59+ ? _keyPrefix + parentPath
60+ : parentPath ) ;
5661
5762 /// <summary>
5863 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
@@ -73,9 +78,7 @@ private void OnWatchCallback(IEnumerable<WatchEvent> events)
7378 Data . Add ( item . Key , item . Value ) ;
7479 }
7580 else
76- {
7781 Data . Remove ( item . Key ) ;
78- }
7982 }
8083 }
8184 }
0 commit comments