0

In my project I have some constants where I reference almost everywhere:

public sealed class Constants{
    public static readonly int MAX_QUAL { get; } = 1080;
    public static readonly bool CC { get; set;} = false;
}

Is it a good practice to store these values in in the application code itself, similar to the snippet above, or in the configuration files (App.config/Web.config/project.json/Manifest.xml etc),

<appSettings>
  <add key="MAX_QUAL" value="1080" />
  <add key="CC" value="false" />
</appsettings>

and then read them through these files on the runtime?

public static readonly int MAX_QUAL { get; } = Convert.ToInt32(
    System.Configuration.ConfigurationManager.AppSettings["MAX_QUAL"]);

I want to structure the application in a way that non-developers can change these values if it is neccessary, without having to change the source code itself. One scenario is when the provider changes the SDK key while the developer is out for vacation, and someone needs to update these values.

Hanjun Chen
  • 113
  • 1
  • 2

1 Answers1

0

I want to structure the application in a way that non-developers can change these values if it is necessary

Yes, the easiest way is a config file. You could also consider

  • command line arguments
  • a database or service which is queried
  • hidden files, perhaps in App_Data but with a UI to change them
Ewan
  • 70,664
  • 5
  • 76
  • 161