56 lines
1.9 KiB
C#
56 lines
1.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace Pos.Dispatcher.Database
|
|
{
|
|
public class LoadConfig
|
|
{
|
|
private string dir;
|
|
public LoadConfig()
|
|
{
|
|
dir = AppDomain.CurrentDomain.BaseDirectory;
|
|
}
|
|
public IConfiguration ByEnvironment()
|
|
{
|
|
//Console.Out.WriteLine($"Json path: {dir}");
|
|
#if DEBUG
|
|
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(dir)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
return config;
|
|
|
|
#else
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(dir)
|
|
.AddJsonFile("appsettings.Production.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
return config;
|
|
#endif
|
|
//Running in a environment that not is supported in this setup
|
|
throw new Exception("HostingEnvironment is not supported! This config setup only supports Development or Production");
|
|
}
|
|
|
|
public IConfiguration DebugConfiguration()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(dir)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
return config;
|
|
}
|
|
|
|
public IConfiguration ReleaseConfiguration()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(dir)
|
|
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
|
|
.AddJsonFile("appsettings.Production.json", optional: true, reloadOnChange: true)
|
|
.Build();
|
|
return config;
|
|
}
|
|
}
|
|
}
|