mirror of
https://github.com/bitwarden/mobile
synced 2025-12-14 07:13:33 +00:00
Dispost of LiteDatabase instance (#928)
This commit is contained in:
@@ -2,12 +2,13 @@
|
||||
using LiteDB;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
public class LiteDbStorageService : IStorageService
|
||||
public class LiteDbStorageService : IStorageService, IDisposable
|
||||
{
|
||||
private readonly JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace Bit.Core.Services
|
||||
private readonly string _dbPath;
|
||||
private ILiteCollection<JsonItem> _collection;
|
||||
private Task _initTask;
|
||||
private LiteDatabase _db;
|
||||
|
||||
public LiteDbStorageService(string dbPath)
|
||||
{
|
||||
@@ -36,8 +38,8 @@ namespace Bit.Core.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
var db = new LiteDatabase($"Filename={_dbPath};Upgrade=true;");
|
||||
_collection = db.GetCollection<JsonItem>("json_items");
|
||||
_db = new LiteDatabase($"Filename={_dbPath};Upgrade=true;");
|
||||
_collection = _db.GetCollection<JsonItem>("json_items");
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -71,6 +73,11 @@ namespace Bit.Core.Services
|
||||
_collection.DeleteMany(i => i.Id == key);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_db?.Dispose();
|
||||
}
|
||||
|
||||
private class JsonItem
|
||||
{
|
||||
public JsonItem() { }
|
||||
|
||||
Reference in New Issue
Block a user