22// Licensed under the MIT license.
33//
44using Microsoft . Extensions . Configuration ;
5+ using Microsoft . Extensions . Logging ;
56using Microsoft . Extensions . Primitives ;
67using System ;
78using System . Collections . Concurrent ;
@@ -23,14 +24,17 @@ sealed class ConfigurationFeatureDefinitionProvider : IFeatureDefinitionProvider
2324
2425 private const string FeatureFiltersSectionName = "EnabledFor" ;
2526 private const string RequirementTypeKeyword = "RequirementType" ;
27+ private const string FeatureManagementSectionName = "FeatureManagement" ;
2628 private readonly IConfiguration _configuration ;
2729 private readonly ConcurrentDictionary < string , FeatureDefinition > _definitions ;
2830 private IDisposable _changeSubscription ;
31+ private readonly ILogger _logger ;
2932 private int _stale = 0 ;
3033
31- public ConfigurationFeatureDefinitionProvider ( IConfiguration configuration )
34+ public ConfigurationFeatureDefinitionProvider ( IConfiguration configuration , ILoggerFactory loggerFactory )
3235 {
3336 _configuration = configuration ?? throw new ArgumentNullException ( nameof ( configuration ) ) ;
37+ _logger = loggerFactory ? . CreateLogger < ConfigurationFeatureDefinitionProvider > ( ) ?? throw new ArgumentNullException ( nameof ( loggerFactory ) ) ;
3438 _definitions = new ConcurrentDictionary < string , FeatureDefinition > ( ) ;
3539
3640 _changeSubscription = ChangeToken . OnChange (
@@ -199,18 +203,18 @@ We support
199203
200204 private IEnumerable < IConfigurationSection > GetFeatureDefinitionSections ( )
201205 {
202- const string FeatureManagementSectionName = "FeatureManagement" ;
206+ //
207+ // Look for feature definitions under the "FeatureManagement" section
208+ IConfigurationSection featureManagementConfigurationSection = _configuration . GetSection ( FeatureManagementSectionName ) ;
203209
204- if ( _configuration . GetChildren ( ) . Any ( s => s . Key . Equals ( FeatureManagementSectionName , StringComparison . OrdinalIgnoreCase ) ) )
210+ if ( featureManagementConfigurationSection . Exists ( ) )
205211 {
206- //
207- // Look for feature definitions under the "FeatureManagement" section
208- return _configuration . GetSection ( FeatureManagementSectionName ) . GetChildren ( ) ;
209- }
210- else
211- {
212- return _configuration . GetChildren ( ) ;
212+ return featureManagementConfigurationSection . GetChildren ( ) ;
213213 }
214+
215+ _logger . LogDebug ( $ "No configuration section named '{ FeatureManagementSectionName } ' was found.") ;
216+
217+ return Enumerable . Empty < IConfigurationSection > ( ) ;
214218 }
215219 }
216220}
0 commit comments