diff --git a/src/Repository/JsonRepository.cs b/src/Repository/JsonRepository.cs index 3f4f069..8d2c58f 100644 --- a/src/Repository/JsonRepository.cs +++ b/src/Repository/JsonRepository.cs @@ -6,6 +6,7 @@ namespace Repository; public class JsonRepository : IRepository, IDisposable { private const string _appName = "Keychain"; + private const string fileName = "password_stores.json"; private uint _autoIncrementedId; private readonly string _filePath; @@ -33,6 +34,9 @@ public class JsonRepository : IRepository, IDisposable var lastItem = _cache.OrderBy(item => item.ID).LastOrDefault(); _autoIncrementedId = lastItem != null ? lastItem.ID : 0; + + // Ensure Dispose is called when the process exits + AppDomain.CurrentDomain.ProcessExit += (s, e) => Dispose(); } private void ReadAllFromFile() @@ -91,8 +95,6 @@ public class JsonRepository : IRepository, IDisposable { WriteToStdErr($"Unexpected error: {e.Message}"); } - - ReadAllFromFile(); } }