C
Join ServerC#
help
Dynamic settings (auto update)
Zzuf10/12/2022
Hey! To put it very basic, I have a static class in my project
The goal is to update this entire class dynamically during run time. To put it very simple, can I just register a worker that pulls the new settings every x minutes and just replaces the
Constants
with a static property Settings
my settings property is a class with a lot of properties such as connection strings and other relevant settings for our app. The goal is to update this entire class dynamically during run time. To put it very simple, can I just register a worker that pulls the new settings every x minutes and just replaces the
Settings
object in my Constants
class or am I going to run into thread safety issues?Zzuf10/12/2022
Trying to achieve https://learn.microsoft.com/en-us/azure/azure-app-configuration/enable-dynamic-configuration-aspnet-core?tabs=core6x#reload-data-from-app-configuration but not using Azure App Configuration
A/CAtakan / Cracker10/12/2022
why do you have connection strings and other configurations that changes so often ?
Zzuf10/12/2022
It was rather a very basic example, we have other settings that we would like to update runtime without restarting the application. Another example would be toggling certain features/functions etc
A/CAtakan / Cracker10/12/2022
Static class doesnt look good solution for me, you can store your configurations in json or config file
A/CAtakan / Cracker10/12/2022
you can create an endpoint which will reload the configuration into application memory when its called
A/CAtakan / Cracker10/12/2022
I assume you would use ConfigurationManager to read json/config file into memory and inject it to your classes
A/CAtakan / Cracker10/12/2022
Once that endpoint triggered, it can call ConfigurationManager.RefreshSection or other helper similar to that
Zzuf10/12/2022
We use a class because its easier to use the values that way, statically typed instead of IConfiguration etc..
A/CAtakan / Cracker10/12/2022
how do you feed that static class, and do you change your configurations manually or its fired from code
A/CAtakan / Cracker10/12/2022
in either case, consider using Config File with ConfigurationManager and ConfigurationManager.RefreshSection. This looks good solution for you imo