From d2edf23274c2c2cdaeb9b16c2aad834d7b52f6b3 Mon Sep 17 00:00:00 2001 From: capdiem Date: Wed, 6 Mar 2024 23:53:11 +0800 Subject: [PATCH] Update --- Masa.Blazor.Pro.Components/Data/ProDatabase.cs | 15 ++++++++++++--- ProApp/MauiProgram.cs | 6 ++++-- ProApp/ProApp.csproj | 1 + 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Masa.Blazor.Pro.Components/Data/ProDatabase.cs b/Masa.Blazor.Pro.Components/Data/ProDatabase.cs index 688a7d4..5373e98 100644 --- a/Masa.Blazor.Pro.Components/Data/ProDatabase.cs +++ b/Masa.Blazor.Pro.Components/Data/ProDatabase.cs @@ -17,8 +17,17 @@ public class ProDatabase // enable multi-threaded database access SQLiteOpenFlags.SharedCache; - // public static string DatabasePath => - // Path.Combine(FileSystem.AppDataDirectory, DatabaseFilename); + public ProDatabase() + { + DatabasePath = DatabaseFilename; + } + + public ProDatabase(string dir) + { + DatabasePath = Path.Combine(dir, DatabaseFilename); + } + + public string DatabasePath { get; private set; } private SQLiteAsyncConnection? Database { get; set; } @@ -30,7 +39,7 @@ async Task InitAsync() return; } - Database = new SQLiteAsyncConnection(DatabaseFilename, Flags); + Database = new SQLiteAsyncConnection(DatabasePath, Flags); await Database.CreateTableAsync(); await Database.CreateTableAsync(); } diff --git a/ProApp/MauiProgram.cs b/ProApp/MauiProgram.cs index 5b6ad82..7cb11cf 100644 --- a/ProApp/MauiProgram.cs +++ b/ProApp/MauiProgram.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.Logging; +using Masa.Blazor.Pro.Components; +using Microsoft.Extensions.Logging; namespace ProApp { @@ -15,7 +16,8 @@ public static MauiApp CreateMauiApp() }); builder.Services.AddMauiBlazorWebView(); - builder.Services.AddMasaBlazor(); + builder.Services.AddMasaBlazorPro(); + builder.Services.AddSingleton(_ = new ProDatabase(FileSystem.AppDataDirectory)); builder.Services.AddLogging(logging => { diff --git a/ProApp/ProApp.csproj b/ProApp/ProApp.csproj index ea28536..b82587a 100644 --- a/ProApp/ProApp.csproj +++ b/ProApp/ProApp.csproj @@ -62,6 +62,7 @@ +