dimanche 1 août 2021

Why use IConfigurationSource to wrap IConfigurationProvider?

Below is some code from asp.net core:

public static class EnvironmentVariablesExtensions {
   ...
   public static IConfigurationBuilder AddEnvironmentVariables( this IConfigurationBuilder configurationBuilder, string prefix) {
      configurationBuilder.Add(new EnvironmentVariablesConfigurationSource { Prefix = prefix });
      return configurationBuilder;
   }
}

public class EnvironmentVariablesConfigurationSource : IConfigurationSource {
   public string Prefix { get; set; }

   public IConfigurationProvider Build(IConfigurationBuilder builder) {
      return new EnvironmentVariablesConfigurationProvider(Prefix);
   }
}

public class EnvironmentVariablesConfigurationProvider : ConfigurationProvider {
   ...
}

public abstract class ConfigurationProvider : IConfigurationProvider {
   ...
}

public interface IConfigurationSource {
   IConfigurationProvider Build(IConfigurationBuilder builder);
}

My question is, why .net team use IConfigurationSource to wrap IConfigurationProvider? Isn't it more concise to get rid of IConfigurationSource, and replace any method signature that need IConfigurationSource to IConfigurationProvider? what's the purpose of IConfigurationSource?

Aucun commentaire:

Enregistrer un commentaire