A:全局Common的公共定义
This commit is contained in:
1 parent
83b7ca5971
commit
eaaedd48cf
18 files changed
+366
-1
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace Common.Configuration;
|
||||
|
||||
public static class ConfigLoader
|
||||
{
|
||||
private static readonly object _lock = new();
|
||||
private static AppConfig _config;
|
||||
|
||||
public static AppConfig Config
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_config == null)
|
||||
{
|
||||
lock (_lock)
|
||||
{
|
||||
if (_config == null)
|
||||
{
|
||||
var builder = new ConfigurationBuilder()
|
||||
.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
|
||||
IConfiguration configuration = builder.Build();
|
||||
|
||||
// _config = new AppConfig();
|
||||
configuration.GetSection("AppSettings").Bind(_config);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _config;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user