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,19 @@ 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+ const string ParseValueErrorString = "Invalid setting '{0}' with value '{1}' for feature '{2}'." ;
35+
36+ public ConfigurationFeatureDefinitionProvider ( IConfiguration configuration , ILoggerFactory loggerFactory )
3237 {
3338 _configuration = configuration ?? throw new ArgumentNullException ( nameof ( configuration ) ) ;
39+ _logger = loggerFactory . CreateLogger < ConfigurationFeatureDefinitionProvider > ( ) ;
3440 _definitions = new ConcurrentDictionary < string , FeatureDefinition > ( ) ;
3541
3642 _changeSubscription = ChangeToken . OnChange (
@@ -199,17 +205,19 @@ We support
199205
200206 private IEnumerable < IConfigurationSection > GetFeatureDefinitionSections ( )
201207 {
202- const string FeatureManagementSectionName = "FeatureManagement" ;
208+ //
209+ // Look for feature definitions under the "FeatureManagement" section
210+ IConfigurationSection featureManagementConfigurationSection = _configuration . GetSection ( FeatureManagementSectionName ) ;
203211
204- if ( _configuration . GetChildren ( ) . Any ( s => s . Key . Equals ( FeatureManagementSectionName , StringComparison . OrdinalIgnoreCase ) ) )
212+ if ( featureManagementConfigurationSection . Exists ( ) )
205213 {
206- //
207- // Look for feature definitions under the "FeatureManagement" section
208- return _configuration . GetSection ( FeatureManagementSectionName ) . GetChildren ( ) ;
214+ return featureManagementConfigurationSection . GetChildren ( ) ;
209215 }
210216 else
211217 {
212- return _configuration . GetChildren ( ) ;
218+ _logger . LogWarning ( $ "No configuration section named '{ FeatureManagementSectionName } ' was found.") ;
219+
220+ return Enumerable . Empty < IConfigurationSection > ( ) ;
213221 }
214222 }
215223 }
0 commit comments