public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, config) => { //读取本地配置 var localconfig = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json").Build(); //从本地配置里读取AgileConfig的相关信息 var appId = localconfig["AgileConfig:appId"]; var secret = localconfig["AgileConfig:secret"]; var nodes = localconfig["AgileConfig:nodes"]; //new一个client实例 var configClient = new ConfigClient(appId, secret, nodes); //使用AddAgileConfig配置一个新的IConfigurationSource config.AddAgileConfig(configClient); //找一个变量挂载client实例,以便其他地方可以直接使用实例访问配置 ConfigClient = configClient; //注册配置项修改事件 configClient.ConfigChanged += ConfigClient_ConfigChanged; }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); });
public CommandRunner( IEnsureConnected ensureConnected, IAuthenticationManager authenticationManager, IConfigClient configClient) { this.authenticationManager = authenticationManager; this.configClient = configClient; this.ensureConnected = ensureConnected; }
public static IConfigurationBuilder AddAgileConfig( this IConfigurationBuilder builder, IConfigClient client, Action <ConfigChangedArg> e = null) { if (e != null) { client.ConfigChanged += e; } ConfigClient.Instance = client; return(builder.Add(new AgileConfigSource(client))); }
private void Application_Startup(object sender, StartupEventArgs e) { //跟控制台项目一样,appid等信息取决于你如何获取。你可以写死,可以从配置文件读取,可以从别的web service读取。 var appId = "test_app"; var secret = ""; var nodes = "http://agileconfig.xbaby.xyz:5000"; ConfigClient = new ConfigClient(appId, secret, nodes); ConfigClient.ConnectAsync().GetAwaiter(); }
public Deployments( AppConfig config, ILogger <Deployments> logger, IDeploymentEventLog deploymentLog, ITenantConnectionHelper tenantConnectionHelper, IConfigClient packagesConfigClient) { if (config == null) { throw new ArgumentNullException("config"); } this.tenantHelper = tenantConnectionHelper; this.deploymentLog = deploymentLog; this.logger = logger; this.configClient = packagesConfigClient; }
public GetConfigs( IEnsureAuthenticated ensureAuthenticated, ISimVersionCache simVersionCache, IGetUserIdFromUsername getUserIdFromUsername, IConfigClient configClient, IWriteFile writeFile, IGetCreatedOutputFolder getCreatedOutputFolder, ILogger <GetConfigs> logger) { this.ensureAuthenticated = ensureAuthenticated; this.simVersionCache = simVersionCache; this.getUserIdFromUsername = getUserIdFromUsername; this.configClient = configClient; this.writeFile = writeFile; this.getCreatedOutputFolder = getCreatedOutputFolder; this.logger = logger; }
public GetConfigs( IEnsureAuthenticated ensureAuthenticated, IGetDefaultConfigPath getDefaultConfigPath, ISimVersionCache simVersionCache, ISimVersionClient simVersionClient, IConfigClient configClient, IGetConfigs getConfigs, IWriteFileMock writeFileMock, ILogger <GetConfigs> logger) { this.ensureAuthenticated = ensureAuthenticated; this.getDefaultConfigPath = getDefaultConfigPath; this.simVersionCache = simVersionCache; this.simVersionClient = simVersionClient; this.configClient = configClient; this.getConfigs = getConfigs; this.writeFileMock = writeFileMock; this.logger = logger; }
public HomeController( ILogger <HomeController> logger, IConfiguration configuration, IOptions <DbConfigOptions> dbOptions, IOptionsSnapshot <DbConfigOptions> dbOptionsSnapshot, IOptionsMonitor <DbConfigOptions> dbOptionsMonitor, IConfigClient configClient) { _logger = logger; _IConfigClient = configClient; _IConfiguration = configuration; _dbOptions = dbOptions; _dbOptionsSnapshot = dbOptionsSnapshot; _dbOptionsMonitor = dbOptionsMonitor; _dbOptionsMonitor.OnChange((o, s) => { Console.WriteLine(o.connection); Console.WriteLine(s); }); }
public static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilder(args) .ConfigureAppConfiguration((context, config) => { //new一个client实例 //使用无参构造函数会自动读取本地appsettings.json文件的AgileConfig节点的配置 var configClient = new ConfigClient(); //使用AddAgileConfig配置一个新的IConfigurationSource config.AddAgileConfig(configClient); //找一个变量挂载client实例,以便其他地方可以直接使用实例访问配置 ConfigClient = configClient; //注册配置项修改事件 configClient.ConfigChanged += (arg) => { Console.WriteLine($"action:{arg.Action} key:{arg.Key}"); }; }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); });
public AgileConfigSource(IConfigClient client) { ConfigClient = client; }
public AgileConfigProvider(IConfigClient client) { Client = client as ConfigClient; }
public static IConfigurationBuilder AddAgileConfig( this IConfigurationBuilder builder, IConfigClient client) { return(builder.Add(new AgileConfigSource(client))); }