Central settings in C # for multiple programs

I was recently given a bunch of support programs, and I'm trying to find some help in adopting some of the best practices. These are essentially three independent software programs that use a common DLL to manage the series of settings that all applications use. The DLL works this way: it changes the user settings file (the XML file is stored deep in the user configuration folder on Windows) with the patch file specified by hard-coded (egad!) Path.

The rationale for saving user settings and not application settings is that the DLL can be found in several places (one for each application that will use it), therefore the user settings file is common (if all copies of the DLL are the same compilation), whereas when using application parameters there will be as many app.config files as there are DLL copies.

I am trying to figure out the best way to centralize these configurations and stop the useless file replacement. One approach (in fact, most likely the best approach) is to reverse engineer all 3 applications so that they all use a central dll with their own "app.config". Are there any more recommended places?

+4
source share
4 answers

Have you considered using the Windows registry? We all hate it, but maybe this is the best option in this case, because it is centralized and you can easily share settings between applications.

EDIT . If you do not like the registry (and I do not blame it for it), you can create XML or some other configuration file in a directory in a special application folder. This is how it is done these days, as far as I know.

string appData = Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData)); string folder = "MyApplicationName"; string fileName = "settings.xml"; string path = Path.Combine(Path.Combine(appData, folder), fileName); 
+7
source

For this exact problem, if it is a DLL.Net, you can use the GAC , this will centralize your DLL. All software will know where they can access this DLL. And so you could do less refactoring.

This is only a patch. just for this problem. I would not recommend this for a new development.

GAC on Wikipedia

+2
source

You can use the settings in the shared file, most likely stored in AppData in the user settings folder

The advantage here is that you do not need to change any code at all.

The application will save its settings in its usual configuration file and refer to the common file for dll settings:

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings file="commondll.config"> <add key="KeyToOverride" value="Original" /> <add key="KeyToNotOverride" value="Standard" /> </appSettings> </configuration> 

then in the general commondll.config file:

 <appSettings> <add key="KeyToOverride" value="Overridden" /> <add key="KeyToBeAdded" value="EntirelyNew" /> </appSettings> 
+2
source

All Articles