优化系统启动速度 (#46)

This commit is contained in:
jimojiangdahu 2024-01-02 16:50:38 +08:00 committed by GitHub
parent 949e8ea805
commit 2aeac021c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -81,7 +81,7 @@ namespace IoTGateway
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IOptionsMonitor<Configs> configs, DeviceService deviceService, ModbusSlaveService modbusSlaveService)
public void Configure(IApplicationBuilder app, IOptionsMonitor<Configs> configs)
{
IconFontsHelper.GenerateIconFont();
app.UseExceptionHandler(configs.CurrentValue.ErrorHandler);

View File

@ -1,6 +1,7 @@
using IoTGateway.DataAccess;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using WalkingTec.Mvvm.Core;
@ -11,8 +12,14 @@ namespace Plugin
public static DBTypeEnum DbType;
public static string connnectSetting;
public static Guid? VariableSelectDeviceId, ConfigSelectDeviceId;
public IoTBackgroundService(IConfiguration configRoot)
private readonly IHostApplicationLifetime _appLifeTime;
private readonly IServiceProvider _serviceProvider;
public IoTBackgroundService(IConfiguration configRoot, IHostApplicationLifetime appLifeTime, IServiceProvider serviceProvider)
{
_appLifeTime = appLifeTime;
_serviceProvider = serviceProvider;
var connnectSettings = new List<ConnnectSettingsModel>();
configRoot.Bind("Connections", connnectSettings);
connnectSetting = connnectSettings[0].Value;
@ -53,6 +60,7 @@ namespace Plugin
}
public override Task StartAsync(CancellationToken cancellationToken)
{
_appLifeTime.ApplicationStarted.Register(OnStarted);
return Task.CompletedTask;
}
@ -60,5 +68,10 @@ namespace Plugin
{
return Task.CompletedTask;
}
private void OnStarted()
{
_ = _serviceProvider.GetRequiredService<DeviceService>();
_ = _serviceProvider.GetRequiredService<ModbusSlaveService>();
}
}
}