Added a data context factory to abstract the database creation process
This commit is contained in:
parent
12eecf9fe0
commit
d53966501a
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace DataModel.Database.Common;
|
namespace DataModel.Database.Common;
|
||||||
|
|
||||||
public sealed class DataContext : DbContext
|
public sealed class DataContext : DbContext, IDataContext
|
||||||
{
|
{
|
||||||
public DbSet<Setting> Settings { get; set; }
|
public DbSet<Setting> Settings { get; set; }
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
14
I18N Commander/DataModel/Database/Common/IDataContext.cs
Normal file
14
I18N Commander/DataModel/Database/Common/IDataContext.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace DataModel.Database.Common;
|
||||||
|
|
||||||
|
public interface IDataContext
|
||||||
|
{
|
||||||
|
public DbSet<Setting> Settings { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Section> Sections { get; set; }
|
||||||
|
|
||||||
|
public DbSet<TextElement> TextElements { get; set; }
|
||||||
|
|
||||||
|
public DbSet<Translation> Translations { get; set; }
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.Maui.LifecycleEvents;
|
using DataModel.Database.Common;
|
||||||
|
using Microsoft.Maui.LifecycleEvents;
|
||||||
|
|
||||||
#if WINDOWS
|
#if WINDOWS
|
||||||
using Microsoft.UI;
|
using Microsoft.UI;
|
||||||
@ -39,6 +40,7 @@ public static class MauiProgram
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
builder.Services.AddMauiBlazorWebView();
|
builder.Services.AddMauiBlazorWebView();
|
||||||
|
builder.Services.AddSingleton<DataContextFactory>();
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
builder.Services.AddBlazorWebViewDeveloperTools();
|
builder.Services.AddBlazorWebViewDeveloperTools();
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using DataModel.Database.Common;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
|
||||||
namespace UI_MAUI.Pages;
|
namespace UI_MAUI.Pages;
|
||||||
|
|
||||||
@ -7,6 +9,9 @@ public partial class LoadProject
|
|||||||
{
|
{
|
||||||
private readonly List<RecentProject> recentProjects = new();
|
private readonly List<RecentProject> recentProjects = new();
|
||||||
|
|
||||||
|
[Inject]
|
||||||
|
public DataContextFactory DataContextFactory { get; set; }
|
||||||
|
|
||||||
private string newProjectName = string.Empty;
|
private string newProjectName = string.Empty;
|
||||||
private string newProjectDestination = string.Empty;
|
private string newProjectDestination = string.Empty;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user