SubstitutingConfigurationSource.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using Microsoft.Extensions.Configuration;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace EasyDevCore.Configuration
  8. {
  9. /// <summary>
  10. ///
  11. /// </summary>
  12. /// <seealso cref="Microsoft.Extensions.Configuration.IConfigurationSource" />
  13. public class SubstitutingConfigurationSource : IConfigurationSource
  14. {
  15. /// <summary>
  16. /// The configuration root
  17. /// </summary>
  18. private readonly IConfigurationRoot _configurationRoot;
  19. /// <summary>
  20. /// The constant section
  21. /// </summary>
  22. private readonly string _variablesSection;
  23. /// <summary>
  24. /// Initializes a new instance of the <see cref="SubstitutingConfigurationSource"/> class.
  25. /// </summary>
  26. /// <param name="configurationRoot">The configuration root.</param>
  27. /// <param name="variablesSection">The variables section.</param>
  28. public SubstitutingConfigurationSource(IConfigurationRoot configurationRoot, string variablesSection)
  29. {
  30. _configurationRoot = configurationRoot;
  31. _variablesSection = variablesSection;
  32. }
  33. /// <summary>
  34. /// Builds the <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider" /> for this source.
  35. /// </summary>
  36. /// <param name="builder">The <see cref="T:Microsoft.Extensions.Configuration.IConfigurationBuilder" />.</param>
  37. /// <returns>
  38. /// An <see cref="T:Microsoft.Extensions.Configuration.IConfigurationProvider" />
  39. /// </returns>
  40. public IConfigurationProvider Build(IConfigurationBuilder builder)
  41. {
  42. return new SubstitutingConfigurationProvider(_configurationRoot, _variablesSection);
  43. }
  44. }
  45. }