diff --git a/I18N Commander/DataModel/Setup.cs b/I18N Commander/DataModel/Setup.cs index 2b87b24..6144126 100644 --- a/I18N Commander/DataModel/Setup.cs +++ b/I18N Commander/DataModel/Setup.cs @@ -37,6 +37,25 @@ public static class Setup Setup.usedDataFile = path2DataFile; serviceCollection.AddDbContext(options => options.UseSqlite($"Filename={path2DataFile};Mode={(createWhenNecessary ? DB_READ_WRITE_CREATE_MODE : DB_READ_WRITE_MODE)};"), ServiceLifetime.Transient); } + + /// + /// Create the database instance from the given path. + /// + public static DataContext CreateDatabaseInstance(string path2DataFile, bool createWhenNecessary = true) + { + // Store the path to the database: + Setup.usedDataFile = path2DataFile; + + // Create a database builder: + var builder = new DbContextOptionsBuilder(); + + // Add the database configuration to the builder: + builder.UseSqlite($"Filename={path2DataFile};Mode={(createWhenNecessary ? DB_READ_WRITE_CREATE_MODE : DB_READ_WRITE_MODE)};"); + + // Next, construct the database context: + var dbContext = new DataContext(builder.Options); + return dbContext; + } /// /// Sets up the DI & db context ready for the EF tooling.