Configuring a library

  • Thread starter Thread starter Jona Gold
  • Start date Start date
J

Jona Gold

I have an argument with a senior programmer here. He says
I shouldn't have special configuration for the part of
the code that's in the library. But isn't that the whole
point of libraries: that you can separate concerns, that
you can change the library, without needing to recompile
all the applications that use it?

My library needs a database DSN. Why should application
initialize it with DSN, instead of special configuration
object? If requirements change, I can simply change or
add settings in the configuration, recompile the library
and leave the applications untouched.

What should I say on the next meeting so that this guy will
stop pushing his twisted design on me? Please help.

Regards, Jona
 
Since you mention recompiling, it isn't clear where you are planning
on putting this configuration...

But: use a setting in a .config file (web.config/app.config); that way
you don't have to recompile the library or the application - you just
change the .config. For database, configuration/connectionStrings
would be the obvious place...

Marc
 
You should not have a separate config file for the dll, but rather let the
calling application set configuration items for your dll. In your example,
it would be good to have a method called SetDSN(string connString); which
replaces the need for the config file you describe. This gets arround
recompiling, and aleviates the need for the application to have a separate
config file to worry about during installation.
 
Marc said:
But: use a setting in a .config file (web.config/app.config); that way
you don't have to recompile the library or the application - you just
change the .config. For database, configuration/connectionStrings
would be the obvious place...

Thanks Marc. There will be couple applications on the server. We
don't want to force admins to use regedit or notepad, so we prepared
a fool-proof configuration editor.

With this editor there comes a library, so that all the applications
can access the configuration uniformly, no matter if it resides in a
..config file, registry or where ever.

Thinking about it again - it's plain stupid, but there is a windows
service and a web application part of one and the same application, and
I'd like to have the configuration in one place. Do I have another option?

Regards,
Jona
 
Family said:
You should not have a separate config file for the dll, but rather let the
calling application set configuration items for your dll. In your example,
it would be good to have a method called SetDSN(string connString); which
replaces the need for the config file you describe. This gets arround
recompiling, and aleviates the need for the application to have a separate
config file to worry about during installation.

Thanks Mike for taking your time. But what if I have to suddenly connect
to another database? I could just change the dll and some options in the
config file. If I followed your advice, I'd have to convert all the
SetDSN calls in all the applications to something like SetDB(user, pass,
IP) and recompile. Isn't that just much more work and a bad design anyway?

Regards,
Jona
 
private void DisplayWebConfig()
{ // Reads in the contents of Web.config and displays them in the
TextBox
StreamReader webConfigStream =
File.OpenText(Path.Combine(Request.PhysicalApplicationPath,
"Web.config"));
string configContents = webConfigStream.ReadToEnd();
webConfigStream.Close();
TextBoxWebConfigContent.Text = configContents;
}
 
private void DisplayWebConfig()
{ // Reads in the contents of Web.config and displays them in the
TextBox
StreamReader webConfigStream =
File.OpenText(Path.Combine(Request.PhysicalApplicationPath,
"Web.config"));
string configContents = webConfigStream.ReadToEnd();
webConfigStream.Close();
TextBoxWebConfigContent.Text = configContents;
}
 
Jona Gold said:
Thanks Mike for taking your time. But what if I have to suddenly connect
to another database? I could just change the dll and some options in the
config file. If I followed your advice, I'd have to convert all the
SetDSN calls in all the applications to something like SetDB(user, pass,
IP) and recompile. Isn't that just much more work and a bad design anyway?

Regards,
Jona

Your main application would likely have the settings in a config file. It
(the application) uses these settings with the DLL API to configure the DLL.
 
Back
Top