From dfd04433c33dae35f90e651163c992df78ae6472 Mon Sep 17 00:00:00 2001 From: sunpengfei <i@angelzzz.com> Date: 星期四, 14 八月 2025 15:52:31 +0800 Subject: [PATCH] feat:开发 --- FlexJobApi.FlexJobServer.Test/Startup.cs | 42 +----------------------------------------- 1 files changed, 1 insertions(+), 41 deletions(-) diff --git a/FlexJobApi.FlexJobServer.Test/Startup.cs b/FlexJobApi.FlexJobServer.Test/Startup.cs index 9d58144..f5da276 100644 --- a/FlexJobApi.FlexJobServer.Test/Startup.cs +++ b/FlexJobApi.FlexJobServer.Test/Startup.cs @@ -18,54 +18,14 @@ { public void ConfigureServices(IServiceCollection services, IConfiguration config) { - services.AddSingleton<IConsulClient, ConsulClient>(p => new ConsulClient(options => - { - var address = config["Consul:Address"] ?? "http://localhost:8500"; - options.Address = new Uri(address); - })); services.AddComponent<DistributedCacheServiceComponent>(); services.AddHttpRemote(); - services.AddSingleton<ResourceHttpUtils>(); } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IConfiguration config) { - var consulClient = app.ApplicationServices.GetRequiredService<IConsulClient>(); - var lifetime = app.ApplicationServices.GetRequiredService<IHostApplicationLifetime>(); + app.UseInject(string.Empty); - // 鏈嶅姟閰嶇疆锛堜粠appsettings.json璇诲彇锛� - var serviceName = config["Consul:ServiceName"] ?? "UnknownService"; - var serviceHost = config["Consul:ServiceIP"] ?? "localhost"; - var servicePort = int.Parse(config["Consul:ServicePort"]); // 鎴栫洿鎺ョ敤鍚姩绔彛 - - // 鏈嶅姟鍞竴ID锛堥伩鍏嶅悓涓�鏈嶅姟澶氬疄渚嬪啿绐侊級 - var serviceId = $"{serviceName}-{serviceHost}-{servicePort}"; - - // 鏈嶅姟娉ㄥ唽淇℃伅 - var registration = new AgentServiceRegistration - { - ID = serviceId, - Name = serviceName, - Address = serviceHost, - Port = servicePort, - // 鍋ュ悍妫�鏌ラ厤缃� - Check = new AgentServiceCheck - { - HTTP = $"http://{serviceHost}:{servicePort}{config["Consul:ServiceHealthCheck"]}", - Interval = TimeSpan.FromSeconds(10), - Timeout = TimeSpan.FromSeconds(5), - DeregisterCriticalServiceAfter = TimeSpan.FromSeconds(30) - } - }; - - // 娉ㄥ唽鏈嶅姟 - consulClient.Agent.ServiceRegister(registration).Wait(); - - // 搴旂敤鍋滄鏃舵敞閿�鏈嶅姟 - lifetime.ApplicationStopping.Register(() => - { - consulClient.Agent.ServiceDeregister(serviceId).Wait(); - }); } } } -- Gitblit v1.9.1