Background service with updatable configuration
So I'm planning/trying to figure out how I'd make a Windows background service. Part of this service would be that it has a configuration file in appdata or something from which it reads certain data, but I also want to be able to update the file while the service is running and have the service recognize the updates and act accordingly. How would I do this in a decent manner? One idea I had is to watch for changes in the file using
FileSystemWatcher
, but idk how "modern" or reliable of an option that is.5 Replies
the built-in configuration pattern has capabilities for this
i believe it's called options monitor? or options snapshot? lemme google
Manoj Choudhari
The Code Blogger
The Code Blogger - IOptionsMonitor Demo – Reload Configurations In ...
reload configurations automatically, options pattern using IOptionsMonitor, in .NET applications
Does this work for files which aren't appsettings.json? Ideally I would like to have the file be a standalone JSON file in appdata or something.
as far as i know, you can use
.AddJsonFile
in the iconfigurationbuilder as many times as you want and they all get collated in
appsettings.json is just a default that gets used when you have a hostbuilder or the likeRight
I haven't used the whole IConfiguration thing a whole lot so I don't know how a lot of this stuff works
I'll research this more