Access Configuration Settings from other Modules
The configuration settings are typically accessed using the Properties class/namespace as follows:string myFolder = Properties.Settings.Default.FolderToUse;
Where the 'FolderToUse' is the property setting specified in the Settings file.
However, these settings can only be accessed in the entry assembly. These settings cannot be accessed from other modules (BL or DL modules).
Use the following technique to allow access to these settings in other modules by passing the settings object to classes in other modules.
In the main method, in the entry module, access one of the existing properties the normal way. If this is not done, the settings do not get loaded.
string someProperty = Properties.Settings.Default.RandomSetting;
It does not seem to matter which property is retrieved.
Pass the settings object using the following. It can be a constructor or a simple method.
public class CustomBL
{
// declare a member variable to hold the settings object
// mark it 'readonly' so that it can only be set in the constructor and then never be changed.
private readonly global::System.Configuration.ApplicationSettingsBase m_ourSettings;
public CustomBL(global::System.Configuration.ApplicationSettingsBase p_Settings)
{
this.m_ourSettings= p_Settings;
}
}
Last modified by Mohit @ 4/12/2025 10:17:20 PM