diff --git a/I18N Commander/DataModel/Database/Common/DataContext.cs b/I18N Commander/DataModel/Database/Common/DataContext.cs index dc6e797..d4155a5 100644 --- a/I18N Commander/DataModel/Database/Common/DataContext.cs +++ b/I18N Commander/DataModel/Database/Common/DataContext.cs @@ -2,7 +2,7 @@ namespace DataModel.Database.Common; -public sealed class DataContext : DbContext +public sealed class DataContext : DbContext, IDataContext { public DbSet Settings { get; set; } diff --git a/I18N Commander/DataModel/Database/Common/DataContextFactory.cs b/I18N Commander/DataModel/Database/Common/DataContextFactory.cs new file mode 100644 index 0000000..566624d --- /dev/null +++ b/I18N Commander/DataModel/Database/Common/DataContextFactory.cs @@ -0,0 +1,11 @@ +namespace DataModel.Database.Common; + +public sealed class DataContextFactory +{ + public IDataContext DataContext { get; private set; } + + public void CreateDataContext(string path2Database) + { + this.DataContext = Setup.CreateDatabaseInstance(path2Database, true); + } +} \ No newline at end of file diff --git a/I18N Commander/DataModel/Database/Common/IDataContext.cs b/I18N Commander/DataModel/Database/Common/IDataContext.cs new file mode 100644 index 0000000..a590766 --- /dev/null +++ b/I18N Commander/DataModel/Database/Common/IDataContext.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; + +namespace DataModel.Database.Common; + +public interface IDataContext +{ + public DbSet Settings { get; set; } + + public DbSet
Sections { get; set; } + + public DbSet TextElements { get; set; } + + public DbSet Translations { get; set; } +} \ No newline at end of file diff --git a/I18N Commander/UI MAUI/MauiProgram.cs b/I18N Commander/UI MAUI/MauiProgram.cs index e68c109..234588f 100644 --- a/I18N Commander/UI MAUI/MauiProgram.cs +++ b/I18N Commander/UI MAUI/MauiProgram.cs @@ -1,4 +1,5 @@ -using Microsoft.Maui.LifecycleEvents; +using DataModel.Database.Common; +using Microsoft.Maui.LifecycleEvents; #if WINDOWS using Microsoft.UI; @@ -39,6 +40,7 @@ public static class MauiProgram #endif builder.Services.AddMauiBlazorWebView(); + builder.Services.AddSingleton(); #if DEBUG builder.Services.AddBlazorWebViewDeveloperTools(); diff --git a/I18N Commander/UI MAUI/Pages/LoadProject.razor.cs b/I18N Commander/UI MAUI/Pages/LoadProject.razor.cs index 58d2496..565de31 100644 --- a/I18N Commander/UI MAUI/Pages/LoadProject.razor.cs +++ b/I18N Commander/UI MAUI/Pages/LoadProject.razor.cs @@ -1,5 +1,7 @@ using System.Text; using System.Text.Json.Serialization; +using DataModel.Database.Common; +using Microsoft.AspNetCore.Components; namespace UI_MAUI.Pages; @@ -7,6 +9,9 @@ public partial class LoadProject { private readonly List recentProjects = new(); + [Inject] + public DataContextFactory DataContextFactory { get; set; } + private string newProjectName = string.Empty; private string newProjectDestination = string.Empty;