示例#1
0
        /// <summary>
        /// 添加Consul配置中心
        /// </summary>
        /// <param name="builder">配置生成器</param>
        /// <param name="consulConfigFile">Consul配置文件。如果传入为null,则默认为Config/consulConfig.json</param>
        /// <param name="options">配置回调</param>
        /// <returns>配置生成器</returns>
        public static IConfigurationBuilder AddConsulConfigCenter(this IConfigurationBuilder builder, string consulConfigFile = "Config/consulConfig.json", Action <ConfigCenterOptions> options = null)
        {
            if (string.IsNullOrWhiteSpace(consulConfigFile))
            {
                throw new ArgumentNullException("Consul配置文件路径不能为空");
            }

            var configOptions = consulConfigFile.ToJsonObjectFromFile <ConfigCenterOptions>();

            if (options != null)
            {
                options(configOptions);
            }
            builder.AddConsulConfigCenter(o =>
            {
                o.FillFrom(configOptions);
            });

            return(builder);
        }