using Cksoft.Data; using Cksoft.Data.Repository; using DllEapBll.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using System; using System.Threading; using System.Threading.Tasks; namespace MQMonitor { class Program { static void Main(string[] args) { var builder = new ConfigurationBuilder().AddJsonFile("appsettings.json"); var configuration = builder.Build(); IServiceCollection services = new ServiceCollection(); services.AddOptions(); //注入 //services.Configure(opts => //{ // configuration.GetSection("AppConfig").Bind(opts); //}); services.AddTransient(); services.AddTransient(t => { return configuration; }); //构建容器 IServiceProvider serviceProvider = services.BuildServiceProvider(); // var config = serviceProvider.GetRequiredService(); var config = serviceProvider.GetRequiredService(); int interval = Convert.ToInt32(configuration["Interval"]); var checkMysqlInterval = Convert.ToInt32(configuration["MysqlCheckInterval"]); Task.Run(() => { while (true) { var service = serviceProvider.GetRequiredService(); service.CheckMysqlSlaveState(); Thread.Sleep(checkMysqlInterval * 60 * 1000); } }); while (true) { var connStr = configuration.GetConnectionString("eap"); using (IDatabase db = DbFactory.Base(connStr, DatabaseType.MySql)) { var service = serviceProvider.GetRequiredService(); service.Monitor(db); Thread.Sleep(interval * 60 * 1000); } } } } }