I'm not sure how to manage configuration settings in a C#/.NET environment. For simplicity lets say I have 3 assemblies: My MainApplication is the project being started and containing the business logic. It references a separate Configuration library, which reads numerous configuration values from a config.xml file that are needed in the MainApplication. Now I have another Library DataProviderWeb, which contains logic to retrieve some data from a webservice and that is loaded by the MainApplication dynamically. Later there should be another DataProvider library that retrieves the data differently. The DataProviderWeb needs some of the config values from the MainApplication and also some specific values (e.g. Webservice address etc.).
Now where is the best place to store the configuration values for the DataProvider in order to make it reusable and achieve low coupling between assemblies?.
I have elaborated multiple possibilities which all have their own drawbacks:
Option 1: All settings are stored in the global config.xml file. DataProviderWeb references Configuration, which reads all settings.
- Then
DataProviderWebis dependent on theConfigurationlibrary, which is speific toMainApplication. Therefore I can't really reuseDataProviderWebin any other Application -> Bad Configurationhas to be aware of implementation specific settings of the DataProvider -> Bad
Option 2: DataProviderWeb has its own config file containing all needed settings.
- Then the settings needed by both the DataProvider and the MainApplication are stored redundant in two different places and I need to make sure they always mach -> Bad
DataProviderWebwould be completely standalone and reusable -> Good
Option 3: All settings are stored in the global config.xml file. The structure of the DataProviderWeb specific settings are defined in a class in the DataProviderWeb dll.
- Configuration needs to reference
DataProviderWebto know the structure of the configuration, therefore it and theMainApplicationare dependent on theDataProviderWeb. AlsoDataProviderWebisn't easily exchangeable for any other library -> Bad - General configuration settings must be defined both in
DataProviderWebandConfigurationso they can be used by both assemblies DataProviderWebwould be completely standalone and reusable -> Good
Option 4: I'm doing this all wrong and should use a completely different approach