mirror of
https://github.com/claunia/romrepomgr.git
synced 2025-12-16 19:24:51 +00:00
Remove database singleton.
This commit is contained in:
@@ -23,37 +23,16 @@
|
||||
// Copyright © 2020 Natalia Portillo
|
||||
*******************************************************************************/
|
||||
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using RomRepoMgr.Database.Models;
|
||||
using RomRepoMgr.Database.Resources;
|
||||
|
||||
namespace RomRepoMgr.Database
|
||||
{
|
||||
public sealed class Context : DbContext
|
||||
{
|
||||
static Context _singleton;
|
||||
|
||||
public Context(DbContextOptions options) : base(options) {}
|
||||
|
||||
public static Context Singleton
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_singleton != null)
|
||||
return _singleton;
|
||||
|
||||
if(Settings.Settings.Current?.DatabasePath is null)
|
||||
throw new ArgumentNullException(nameof(Settings.Settings.Current.DatabasePath),
|
||||
Localization.Settings_not_initialized);
|
||||
|
||||
_singleton = Create(Settings.Settings.Current.DatabasePath);
|
||||
|
||||
return _singleton;
|
||||
}
|
||||
}
|
||||
|
||||
public DbSet<DbFile> Files { get; set; }
|
||||
public DbSet<RomSet> RomSets { get; set; }
|
||||
public DbSet<Machine> Machines { get; set; }
|
||||
@@ -63,8 +42,6 @@ namespace RomRepoMgr.Database
|
||||
public DbSet<DbMedia> Medias { get; set; }
|
||||
public DbSet<MediaByMachine> MediasByMachines { get; set; }
|
||||
|
||||
public static void ReplaceSingleton(string dbPath) => _singleton = Create(dbPath);
|
||||
|
||||
public static Context Create(string dbPath)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder();
|
||||
|
||||
Reference in New Issue
Block a user