benxu.AppPlatform.Storage.LiteDB
3.0.2
dotnet add package benxu.AppPlatform.Storage.LiteDB --version 3.0.2
NuGet\Install-Package benxu.AppPlatform.Storage.LiteDB -Version 3.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="benxu.AppPlatform.Storage.LiteDB" Version="3.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="benxu.AppPlatform.Storage.LiteDB" Version="3.0.2" />
<PackageReference Include="benxu.AppPlatform.Storage.LiteDB" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add benxu.AppPlatform.Storage.LiteDB --version 3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: benxu.AppPlatform.Storage.LiteDB, 3.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package benxu.AppPlatform.Storage.LiteDB@3.0.2
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=benxu.AppPlatform.Storage.LiteDB&version=3.0.2
#tool nuget:?package=benxu.AppPlatform.Storage.LiteDB&version=3.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
benxu.AppPlatform.Storage.LiteDB
LiteDB 本地儲存實作 - 提供 Offline-first 的本地資料庫功能。
特色
- 輕量級 NoSQL 資料庫
- 支援 Key-Value 和 Collection 儲存模式
- 執行緒安全
- 自動序列化/反序列化
- 支援加密
- 封裝連線字串和檔案路徑
安裝
dotnet add package benxu.AppPlatform.Storage.LiteDB
使用範例
註冊服務
using benxu.AppPlatform.Storage.LiteDB.Extensions;
// 使用預設設定
builder.Services.AddLiteDBStorage();
// 或自訂設定
builder.Services.AddLiteDBStorage(new LiteDBOptions
{
DatabaseName = "myapp.db",
EnableEncryption = true,
EncryptionPassword = "your-password"
});
Key-Value 儲存
public class MyService
{
private readonly ILocalStorage _storage;
public MyService(ILocalStorage storage)
{
_storage = storage;
}
public async Task SaveUserSettingsAsync(UserSettings settings)
{
var result = await _storage.SaveAsync("user_settings", settings);
if (result.IsSuccess)
{
Console.WriteLine("設定已儲存");
}
}
public async Task<UserSettings?> LoadUserSettingsAsync()
{
var result = await _storage.GetAsync<UserSettings>("user_settings");
return result.IsSuccess ? result.Data : null;
}
}
Collection 儲存
// 儲存
await _storage.SaveCollectionAsync("todos", new TodoItem
{
Id = 1,
Title = "學習 MAUI"
});
// 查詢
var result = await _storage.QueryCollectionAsync<TodoItem>(
"todos",
item => item.IsCompleted == false
);
// 取得所有
var allTodos = await _storage.GetAllFromCollectionAsync<TodoItem>("todos");
設定選項
public class LiteDBOptions
{
public string DatabaseName { get; set; } = "appplatform.db";
public ConnectionType ConnectionMode { get; set; } = ConnectionType.Shared;
public bool EnableEncryption { get; set; }
public string? EncryptionPassword { get; set; }
public long InitialSize { get; set; }
public bool EnableLogging { get; set; }
}
資料位置
資料庫檔案會儲存在平台的 LocalApplicationData 目錄:
- Windows:
%LOCALAPPDATA% - macOS:
~/Library/Application Support - Android:
/data/data/{package}/files - iOS:
~/Library
授權
MIT License - Copyright (c) 2025 benxu
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net10.0
- benxu.AppPlatform.Core (>= 3.0.2)
- LiteDB (>= 5.0.21)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Xamarin.Build.Download (>= 0.11.4)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on benxu.AppPlatform.Storage.LiteDB:
| Package | Downloads |
|---|---|
|
benxu.AppPlatform.MAUI.Bootstrap
Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management. |
|
|
benxu.AppPlatform.Notification
跨平台通知服務套件,提供 Android 和 iOS 的推播通知、本地通知管理功能,整合 Firebase Cloud Messaging (FCM) 服務,支援通知排程、通知歷程記錄與本地儲存,適用於 .NET MAUI Blazor 應用程式開發。 |
GitHub repositories
This package is not used by any popular GitHub repositories.