/// <summary>
        /// Adds a new configuration source, retrieves the provider for the source, and
        /// adds a change listener that triggers a reload of the provider whenever a change
        /// is detected.
        /// </summary>
        /// <param name="source">The configuration source to add.</param>
        /// <returns>The same <see cref="IConfigurationBuilder"/>.</returns>
        public IConfigurationBuilder Add(IConfigurationSource source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            // Ads this source and its associated provider to the source
            // and provider references in this class. We make sure to load
            // the data from the provider so that values are properly initialized.
            _sources.Add(source);
            var provider = source.Build(this);

            provider.Load();

            // Add a handler that will detect when the the configuration
            // provider has reloaded data. This will invoke the RaiseChanged
            // method which maps changes in individual providers to the change
            // token on the WebAssemblyHostConfiguration object.
            _changeTokenRegistrations.Add(ChangeToken.OnChange(() => provider.GetReloadToken(), () => RaiseChanged()));

            // We keep a list of providers in this class so that we can map
            // set and get methods on this class to the set and get methods
            // on the individual configuration providers.
            _providers.Add(provider);
            return(this);
        }
示例#2
0
        public IConfigurationProvider Build(IConfigurationBuilder builder)
        {
            if (_provider != null)
            {
                return(_provider);
            }

            return(_provider = _source.Build(builder));
        }
 public IConfigurationProvider Build(IConfigurationBuilder builder)
 {
     return(new HookConfigurationProvider(source.Build(builder), hook));
 }