diff --git a/PrivateBox/Forms/MainForm.cs b/PrivateBox/Forms/MainForm.cs index 646e55a..d224c19 100644 --- a/PrivateBox/Forms/MainForm.cs +++ b/PrivateBox/Forms/MainForm.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using Falcon.SugarCore.DbContextExtensions; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PrivateBox.DataContext; using PrivateBox.Encryption; @@ -15,7 +16,6 @@ namespace PrivateBox public AppRunTimeSettings Settings { get; set; } public ILogger Logger { get; set; } - /// /// 默认分组名 /// @@ -28,8 +28,13 @@ namespace PrivateBox /// private bool EnableRefreshKeyList = true; - public MainForm(IServiceProvider provider) { + public MainForm(IServiceScopeFactory factory) { InitializeComponent(); + var serviceScope = factory.CreateScope(); + this.FormClosing += (s,d) => { + serviceScope?.Dispose(); + }; + var provider = serviceScope.ServiceProvider; this.Encrytion = provider.GetRequiredService(); this.Db = provider.GetRequiredService(); this.Settings = provider.GetRequiredService(); @@ -41,6 +46,7 @@ namespace PrivateBox RefreshKeyList(); }; + this.lbKeyList.SelectedIndexChanged += LbKeyList_SelectedIndexChanged; this.clb_group.ItemCheck += (s,e) => { this.BeginInvoke(new Action(() => {