设置修改
This commit is contained in:
parent
88cea58dc3
commit
90e885ce70
@ -1,4 +1,5 @@
|
|||||||
using PrivateBox.DataContext;
|
using Falcon.SugarCore.DbContextExtensions;
|
||||||
|
using PrivateBox.DataContext;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace PrivateBox
|
namespace PrivateBox
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
|
using Falcon.SugarCore;
|
||||||
using Falcon.SugarCore.DbContextExtensions;
|
using Falcon.SugarCore.DbContextExtensions;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PrivateBox.DataContext;
|
||||||
using PrivateBox.Encryption;
|
using PrivateBox.Encryption;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using Falcon.SugarCore;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace PrivateBox
|
namespace PrivateBox
|
||||||
{
|
{
|
||||||
@ -21,13 +22,33 @@ namespace PrivateBox
|
|||||||
services.AddSingleton(appConfig);
|
services.AddSingleton(appConfig);
|
||||||
services.AddSingleton<AppRunTimeSettings>();
|
services.AddSingleton<AppRunTimeSettings>();
|
||||||
AddServices(services,appConfig);
|
AddServices(services,appConfig);
|
||||||
using var providerScope = services.BuildServiceProvider().CreateScope();
|
|
||||||
var sp = providerScope.ServiceProvider;
|
var rootProvider = services.BuildServiceProvider();
|
||||||
var logger = sp.GetRequiredService<ILoggerFactory>().CreateLogger("Main");
|
|
||||||
var mainForm = sp.GetRequiredService<MainForm>();
|
using var appMainScope = rootProvider.CreateScope();
|
||||||
logger.LogInformation($"Application will run main:{mainForm.GetType().FullName}");
|
var mainSp = appMainScope.ServiceProvider;
|
||||||
|
var logger = mainSp.GetRequiredService<ILoggerFactory>().CreateLogger("Main");
|
||||||
|
///初始化
|
||||||
|
using(var initProvider = rootProvider.CreateScope()) {
|
||||||
|
var initsp = initProvider.ServiceProvider;
|
||||||
|
var dbContext = initsp.GetRequiredService<DbContext>();
|
||||||
|
logger?.LogInformation($"数据库初始化开始!");
|
||||||
|
try {
|
||||||
|
DbInitializer.Init(dbContext);
|
||||||
|
}
|
||||||
|
catch(Exception ex) {
|
||||||
|
logger?.LogError(ex,"数据库初始化失败");
|
||||||
|
MessageBox.Show($"数据库初始化失败:{ex.Message}","启动错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger?.LogInformation($"数据库初始化完成");
|
||||||
|
}
|
||||||
|
|
||||||
|
//启动窗体
|
||||||
|
var mainForm = mainSp.GetRequiredService<MainForm>();
|
||||||
|
logger?.LogInformation($"Application will run main:{mainForm.GetType().FullName}");
|
||||||
Application.Run(mainForm);
|
Application.Run(mainForm);
|
||||||
logger.LogInformation($"Application closed main:{mainForm.GetType().FullName}");
|
logger?.LogInformation($"Application closed main:{mainForm.GetType().FullName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void AddServices(IServiceCollection services,AppConfig config) {
|
static void AddServices(IServiceCollection services,AppConfig config) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user