A:配置读取
This commit is contained in:
1 parent
859814514b
commit
727c83da2d
13 files changed
+671
-32
No files matched your search
@@ -3,10 +3,10 @@ using System.Text;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.FileProviders;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using Sharp.Config.Serialization;
|
||||
using Config.Serialization;
|
||||
using Tomlyn.Extensions.Configuration;
|
||||
|
||||
namespace Sharp.Config;
|
||||
namespace Config;
|
||||
|
||||
public sealed class ConfigManager
|
||||
{
|
||||
@@ -47,7 +47,8 @@ public sealed class ConfigManager
|
||||
builder.AddXmlFile(src.Path, src.Optional, options.ReloadOnChange);
|
||||
break;
|
||||
case ConfigFormat.Toml:
|
||||
builder.AddToml(src.Path, src.Optional, options.ReloadOnChange);
|
||||
// Tomlyn.Extensions.Configuration uses AddTomlFile in recent versions
|
||||
builder.AddTomlFile(src.Path, src.Optional, options.ReloadOnChange);
|
||||
break;
|
||||
default:
|
||||
throw new NotSupportedException($"Unsupported format: {src.Format}");
|
||||
@@ -154,8 +155,8 @@ public sealed class ConfigManager
|
||||
// Reload notifications
|
||||
public IDisposable OnReload(Action callback)
|
||||
{
|
||||
IChangeToken token = Configuration.GetReloadToken();
|
||||
return ChangeToken.OnChange(() => token, callback);
|
||||
// 始终基于最新的 ReloadToken 订阅,以支持连续热更新
|
||||
return ChangeToken.OnChange(() => Configuration.GetReloadToken(), callback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,4 +181,3 @@ public sealed class ConfigurationValidationException : Exception
|
||||
Errors = errors;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user