Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can other developer know that class library is using app.config? Or should I just eliminate app.config?

Tags:

c#

.net

Just as an example, I created a class library (Email.DLL) that sends an email. In order to send an email, SmtpClient needs credentials, which are currently being read from app.config.

So now I created a separate console app (SendStuff.exe) that sends an email, so I added Email.dll as reference. Being the one that created both the DLL and the console app, I know that I need to add the appropriate keys in the console app's appSettings of app.config in order for the email to be sent.

Now, let's say that someone else uses the DLL. How would he know that his application needs to include the appropriate appSettings so that my Email.DLL can send the email?

Or would it be better to just eliminate app.config from the class library and find some other way to set the credentials?

like image 869
Joe_Hendricks Avatar asked Sep 29 '14 16:09

Joe_Hendricks


1 Answers

Using the local config file is a perfectly standard approach. Usually, you would include this information in the documentation that accompanies the library. Often, there's a Getting Started or Tutorial page.

With that said, I'd also implement clear and actionable exceptions that are thrown when these configuration values are missing. Something like:

Could not find SMTP credentials in App.config. See documentation for more information.

Lastly, if you distribute your library with something like NuGet, you can automatically include default configurations that will be set when the library is added through the package manager.

like image 54
Mike Christensen Avatar answered Sep 20 '22 22:09

Mike Christensen