namespace Apq.Cfg.Apollo; /// /// CfgBuilder 的 Apollo 扩展方法 /// public static class CfgBuilderExtensions { /// /// 添加 Apollo 配置源 /// /// 配置构建器 /// 配置选项 /// 配置层级,数值越大优先级越高 /// 是否为主写入源(Apollo 不支持写入) /// 配置构建器 public static CfgBuilder AddApollo( this CfgBuilder builder, Action configure, int level, bool isPrimaryWriter = false) { var options = new ApolloCfgOptions(); configure?.Invoke(options); builder.AddSource(new ApolloCfgSource(options, level, isPrimaryWriter)); return builder; } /// /// 添加 Apollo 配置源(使用默认选项) /// /// 配置构建器 /// Apollo 应用 ID /// Meta Server 地址 /// 命名空间列表 /// 配置层级 /// 是否启用热重载 /// 配置构建器 public static CfgBuilder AddApollo( this CfgBuilder builder, string appId, string metaServer = "http://localhost:8080", string[]? namespaces = null, int level = 0, bool enableHotReload = true) { return builder.AddApollo(options => { options.AppId = appId; options.MetaServer = metaServer; options.Namespaces = namespaces ?? ["application"]; options.EnableHotReload = enableHotReload; }, level); } }