Refactor DatabaseContext to be cleaner cause EF is annoying like this.
This commit is contained in:
parent
ae1a15ad32
commit
67bde5a610
@ -20,31 +20,20 @@ namespace ChaosBot
|
||||
{
|
||||
if (!optionsBuilder.IsConfigured)
|
||||
{
|
||||
string server, user, pass, name;
|
||||
int port;
|
||||
IConfiguration appSettingsHandler = Program.AppSettingsHandler;
|
||||
|
||||
if (Program.AppSettingsHandler == null)
|
||||
{
|
||||
IConfiguration config = Program.AppSettingsHandler = new ConfigurationBuilder()
|
||||
appSettingsHandler = new ConfigurationBuilder()
|
||||
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true).Build();
|
||||
|
||||
server = config.GetValue<string>("Database:Host");
|
||||
port = config.GetValue<int>("Database:Port");
|
||||
user = config.GetValue<string>("Database:User");
|
||||
pass = config.GetValue<string>("Database:Pass");
|
||||
name = config.GetValue<string>("Database:Name");
|
||||
}
|
||||
else
|
||||
{
|
||||
ConfigHelpers.Configuration config = new ConfigHelpers.Configuration();
|
||||
|
||||
server = config.GetByKey<string>("Database:Host").GetValue(readRestricted: true);
|
||||
port = config.GetByKey<int>("Database:Port").GetValue(readRestricted: true);
|
||||
user = config.GetByKey<string>("Database:User").GetValue(readRestricted: true);
|
||||
pass = config.GetByKey<string>("Database:Pass").GetValue(readRestricted: true);
|
||||
name = config.GetByKey<string>("Database:Name").GetValue(readRestricted: true);
|
||||
.AddJsonFile(Program.AppSettingsPath).Build();
|
||||
}
|
||||
|
||||
string server = appSettingsHandler.GetValue<string>("Database:Host");
|
||||
int port = appSettingsHandler.GetValue<int>("Database:Port");
|
||||
string user = appSettingsHandler.GetValue<string>("Database:User");
|
||||
string pass = appSettingsHandler.GetValue<string>("Database:Pass");
|
||||
string name = appSettingsHandler.GetValue<string>("Database:Name");
|
||||
|
||||
optionsBuilder.UseMySql(
|
||||
$"server={server};port={port};user={user};password={pass};database={name}",
|
||||
|
||||
@ -15,18 +15,16 @@ namespace ChaosBot
|
||||
private static ILogger _logger;
|
||||
public static IConfiguration AppSettingsHandler;
|
||||
|
||||
private static string _appSettingsPath;
|
||||
public const string AppSettingsPath = "./appsettings.json";
|
||||
|
||||
private static void Main(string[] args)
|
||||
{
|
||||
_appSettingsPath = args.Length > 0 ? args[0] : "./appsettings.json";
|
||||
|
||||
try
|
||||
{
|
||||
/*
|
||||
* Load configuration from AppSettings.Json and save as Cfg
|
||||
*/
|
||||
AppSettingsHandler = LoadConfiguration(_appSettingsPath);
|
||||
AppSettingsHandler = LoadConfiguration(AppSettingsPath);
|
||||
|
||||
/*
|
||||
* Initialize the _logger for logging purposes
|
||||
|
||||
Loading…
Reference in New Issue
Block a user