-
I'm driving myself crazy because this must work, right? This run is a test in a desktop environment. [Fact]
public void FileChangeShouldUpdateConfiguration()
{
var cBuilder = new ConfigurationBuilder();
cBuilder.AddJsonFile("config.json", false, true);
var config = cBuilder.Build();
var token = config.GetReloadToken();
token.RegisterChangeCallback((c) =>
{
//this fragment is never called, and the configuration never reloads on his own
}, null);
var value = config["database_config:port"];
var jsonOriginalText = File.ReadAllText($"{Environment.CurrentDirectory}/config.json");
var jobject = JsonNode.Parse(jsonOriginalText);
jobject!["database_config:port"] = Random.Shared.Next(0, 10000);
File.WriteAllText($"{Environment.CurrentDirectory}/config.json", jobject.ToJsonString());
var jsonNewText = File.ReadAllText($"{Environment.CurrentDirectory}/config.json");
var newVal = config["database_config:port"];
Assert.NotEqual(value, newVal);
} No exceptions, no problems, only the configuration never updates itself. If I call |
Beta Was this translation helpful? Give feedback.
Answered by
KeterSCP
Aug 11, 2023
Replies: 1 comment 1 reply
-
Seems like ConfigurationBuilder uses |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
DrkWzrd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Seems like ConfigurationBuilder uses
FileSystemWatcher
to detect changes on configs. And it can fire events with some delay and not immediately after a file was written. You can see that by simply addingThread.Sleep(500);
afterFile.WriteAllText