C
C#12mo ago
Pokey

❔ Check if appsettings.json or appsettings.Development.json

I need to write settings back to my configuration json during the operation of the current application. To achieve this, I open the appsettings.json file and write the newly serialised values. This works perfectly in production, but causes issues in development. How can I tell which json file the current application is using at the topmost level? I know it is appsettings.Development.json when running in a development context, but I have not found a way to determine this whilst the application is running. Thanks
6 Replies
jcotton42
jcotton4212mo ago
appsettinngs, and the entire config stack aren't really meant for mutable settings Especially since it's meant to be layered
Pokey
Pokey12mo ago
Indeed, which is why I have an entire config layer in the application to handle that immutability When the application starts up, it uses the Microsoft stuff to load the configuration in, and then brings that into an object in memory. When settings are saved, they are immediately applied live because the object is updated live and is referenced by everything. For the persistence, it is written back to the file for the next time the application starts up Right now to work around my issue, I have done a dirty hack where I specify the filename of the config... in the config works fine but not ideal
Mayor McCheese
Mayor McCheese12mo ago
Some sources are meant to refresh, like azure app configuration
jcotton42
jcotton4212mo ago
Yeah, but the app isn't meant to be the one modifying it, is what I meant
Mayor McCheese
Mayor McCheese12mo ago
iirc there is some facility for read-write; but honestly even if there is; don't use it. there are better options than abusing the hell out of configuration settings
Accord
Accord12mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.