public RemoteConfigurationProvider(RemoteConfigurationSource source) { Check.NotNull(source, "source"); if (!string.IsNullOrEmpty(source.ConfigurationKeyPrefix)) { Check.CheckCondition(() => source.ConfigurationKeyPrefix.Trim().StartsWith(":"), CachingResources.InvalidStartCharacter, "source.ConfigurationKeyPrefix", ":"); Check.CheckCondition(() => source.ConfigurationKeyPrefix.Trim().EndsWith(":"), CachingResources.InvalidEndCharacter, "source.ConfigurationKeyPrefix", ":"); } Source = source; Backchannel = new HttpClient(source.BackchannelHttpHandler ?? new HttpClientHandler()); Backchannel.DefaultRequestHeaders.UserAgent.ParseAdd("获取CacheConfiugration信息"); Backchannel.Timeout = source.BackchannelTimeout; Backchannel.MaxResponseContentBufferSize = 1024 * 1024 * 10; Parser = source.Parser ?? new JsonConfigurationParser(); }
/// <summary> ///对于 <paramref name="builder"/>添加远程配置方法 /// </summary> /// <param name="builder"><see cref="IConfigurationBuilder"/></param> /// <param name="configurationUri">远程地址</param> /// <param name="optional">远程配置源是否可选</param> /// <returns>The <see cref="IConfigurationBuilder"/>.</returns> public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder builder, Uri configurationUri, bool optional) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (configurationUri == null) { throw new ArgumentNullException(nameof(configurationUri)); } var source = new RemoteConfigurationSource { ConfigurationUri = configurationUri, Optional = optional, }; return(builder.AddRemoteSource(source)); }
/// <summary> ///对于 <paramref name="builder"/>添加远程配置方法 /// </summary> /// <param name="builder"> <see cref="IConfigurationBuilder"/></param> /// <param name="source"> <see cref="RemoteConfigurationSource"/></param> /// <returns><see cref="IConfigurationBuilder"/></returns> public static IConfigurationBuilder AddRemoteSource(this IConfigurationBuilder builder, RemoteConfigurationSource source) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (source == null) { throw new ArgumentNullException(nameof(source)); } builder.Add(source); return(builder); }