From de93e998845572fb8eef4d5c623edcd26a54b4f8 Mon Sep 17 00:00:00 2001 From: support Date: Mon, 24 Jul 2023 19:56:01 +0200 Subject: [PATCH] Change the location DbConnectionString settings in appsettings for installed database (settings only for advanced administrators) --- .../Grand.Infrastructure/Configuration/AdvancedConfig.cs | 3 --- .../Grand.Infrastructure/Configuration/DatabaseConfig.cs | 7 +++++++ src/Core/Grand.Infrastructure/StartupBase.cs | 8 ++++---- src/Web/Grand.Web/App_Data/appsettings.json | 7 ++++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Core/Grand.Infrastructure/Configuration/AdvancedConfig.cs b/src/Core/Grand.Infrastructure/Configuration/AdvancedConfig.cs index a02ca1c81..f56e840c9 100644 --- a/src/Core/Grand.Infrastructure/Configuration/AdvancedConfig.cs +++ b/src/Core/Grand.Infrastructure/Configuration/AdvancedConfig.cs @@ -2,9 +2,6 @@ { public class AdvancedConfig { - public string DbConnectionString { get; set; } - public int DbProvider { get; set; } public string InstalledPlugins { get; set; } - } } diff --git a/src/Core/Grand.Infrastructure/Configuration/DatabaseConfig.cs b/src/Core/Grand.Infrastructure/Configuration/DatabaseConfig.cs index 5f0e848de..26987a950 100644 --- a/src/Core/Grand.Infrastructure/Configuration/DatabaseConfig.cs +++ b/src/Core/Grand.Infrastructure/Configuration/DatabaseConfig.cs @@ -16,5 +16,12 @@ public class DatabaseConfig /// Gets or sets a value indicating whether use LiteDB database (only for installation process) /// public string LiteDbConnectionString { get; set; } + + /// + /// Gets or sets a value indicating whether use connection string for database (only for installed databases) + /// + public string DbConnectionString { get; set; } + public int DbProvider { get; set; } + } } diff --git a/src/Core/Grand.Infrastructure/StartupBase.cs b/src/Core/Grand.Infrastructure/StartupBase.cs index 55e890185..81d7a797a 100644 --- a/src/Core/Grand.Infrastructure/StartupBase.cs +++ b/src/Core/Grand.Infrastructure/StartupBase.cs @@ -35,12 +35,12 @@ public static class StartupBase /// private static void InitDatabase(IServiceCollection services, IConfiguration configuration) { - var advancedConfig = services.StartupConfig(configuration.GetSection("Advanced")); - if (!string.IsNullOrEmpty(advancedConfig.DbConnectionString)) + var dbConfig = services.StartupConfig(configuration.GetSection("Database")); + if (!string.IsNullOrEmpty(dbConfig.DbConnectionString)) { DataSettingsManager.LoadDataSettings(new DataSettings { - ConnectionString = advancedConfig.DbConnectionString, - DbProvider = (DbProvider)advancedConfig.DbProvider + ConnectionString = dbConfig.DbConnectionString, + DbProvider = (DbProvider)dbConfig.DbProvider }); } } diff --git a/src/Web/Grand.Web/App_Data/appsettings.json b/src/Web/Grand.Web/App_Data/appsettings.json index 887e81f66..abd8d6ba8 100644 --- a/src/Web/Grand.Web/App_Data/appsettings.json +++ b/src/Web/Grand.Web/App_Data/appsettings.json @@ -39,7 +39,10 @@ //LiteDB database as a singleton service in the application "Singleton": true, //Init connection string - it's required only for the installation process! - "LiteDbConnectionString": "Filename=App_Data/database.db" + "LiteDbConnectionString": "Filename=App_Data/database.db", + //only for advanced users, allow to set ConnectionString for MongoDb + "DbConnectionString": "", + "DbProvider": 0 }, "Security": { @@ -242,8 +245,6 @@ "UseSwagger": false, //Settings only for advanced users "Advanced": { - "DbConnectionString": "", - "DbProvider": 0, //separator comma "InstalledPlugins": "" },