Wil
Wil

Reputation: 2358

Best way to store configuration settings outside of web.config

I'm starting to consider creating a class library that I want to make generic so others can use it. While planning it out, I came to thinking about the various configuration settings that I would need. Since the idea is to make it open/shared, I wanted to make things as easy on the end user as possible. What's the best way to setup configuration settings without making use of web.config/app.config?

Upvotes: 5

Views: 1392

Answers (3)

Syd
Syd

Reputation: 1546

If you are worried about all the other tags in web.config, why don't you "include" your configuration file that contains only those settings that your users would customise?

The syntax is

<include uri="your file.xml" />

By having your "file.xml" outside of web.config, you prevent common mistakes by your users to modify your web.config inadvertably.

Upvotes: 0

Claudio Redi
Claudio Redi

Reputation: 68400

I think it's not wrong to use the web.config for storing you configuration items. But you could be more flexible offering 3 configuration options as many popular libraries do (nhibernate, log4net, etc)

  • Use Web.config
  • Use a external xml file
  • Configure library programatically

Doing it like this you leave the decision on your library users instead of supposing they won't be happy using the web.config.

Upvotes: 3

BoltBait
BoltBait

Reputation: 11489

Why are you rejecting the use of web.config/app.config? That's what they're for, and that's totally the way I'd do it.

Put an example block of code for the web.config/app.config in your documantation that could be copy-and-pasted into the real config file. If documented well, it shouldn't really be a problem for your users.

Just be sure you don't crash because the settings don't exist. Or, if you do crash, give a detailed error message telling the user to edit the proper config file and where in the documentation they can find examples. That would make it easier on your user.

Upvotes: 6

Related Questions