mirror of
https://gitee.com/iioter/iotgateway.git
synced 2024-11-29 18:28:09 +08:00
优化系统启动速度 (#46)
This commit is contained in:
parent
949e8ea805
commit
2aeac021c6
@ -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);
|
||||
|
@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user