Reputation: 1729
I'm creating client server application using windows form. All application configuration is saved in database table, named Configuration, and there is interface to change its value. There are some records in configuration's table is used in transaction, for example "Log Activation". If this value of Log Activation is true, then when saved a transaction it will create a log file.
So, when every times I saved a transaction, I always read the Log Activation configuration to the database to get its value. In my case, I'm not only read 1 configuration, but I can read 1 or more configuration. My concern is there will be many database round trip to get each configuration values and it's not good design in client-server architecture.
Then I tried to use Settings File, but this approach is not fit to my application, because I develop client-server application using Windows Form. Every time I updated the value in Settings file, it only affected in that computer, and the others do not.
So what is the best solution to solve this problem rather than read directly to database in each transactions?
Upvotes: 0
Views: 472
Reputation: 56697
It really depends on how your configuration mechanism should work. Should the current configuration value be used at all occasions or would it suffice to detect configuration changes after restarting the application?
In the first case, you will need to read the required value just before you need it, just like you do now.
In the second case it would be enough to create a public static class that has one member per setting and is able to both set a new value and read all the values when the application starts. The drawback, as I said, is that settings aren't applied until all clients restart.
Example class for the latter:
public static final class Configuration
{
private static string m_setting1;
private static bool m_setting2;
static Configuration()
{
// Read all settings
...
}
public static string Setting1
{
get { return m_setting1; }
set
{
if (!m_setting1.Equals(value))
{
m_setting1 = value;
StoreSettings();
}
}
}
public static bool Setting2
{
get { rteurn m_setting2; }
set
{
if (!m_setting2 == value)
{
m_setting2 = value;
StoreSettings();
}
}
}
Upvotes: 1