views:

33

answers:

3

Ok I know this may be a design issue, so I would love to have remarks on that as well.

I have a Visual Studio web application solution. I have three projects as UserInterface, BusinessLogic and DataAccess.

I had to store some user defined settings and I created configSections in the config file.

I access these configSections through classes which inherit from .NET's ConfigurationSection base class.

So in short for every project I had a separate configSection and for that corresponding configSection I had a class in that project inheriting from ConfigurationSection to access the config section settings.

This works all sweet. But the problem arises if there is any setting which I need to use across multiple projects. So If I need to use a setting defined in UserInterface project configSection in, let say, BusinessLogic project I have to actually make a copy of that setting in the BusinessLogic's configSection. This ends up having the same setting copied across multiple configSections.

Isn't this a bit too redundant?

+1  A: 

Put shared config settings in a separate file and use this technique: http://blogs.msdn.com/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx

simon831
Need to keep that link, describes linked files very well.
Will
Hmm. Isn't that very much like creating a 'Common' Project and putting the shared settings in it. And then rest of the projects could access that Common for it ?
nEEbz
A: 

Using your example:

Just create the setting in the Business Logic project and then expose a Getter to the User Interface project.

Then the UI can query the BL for the value. Your configuration setting is only in one place - the lowest level it can be.

However, if you replace a lower level project with a new one you'll have to make sure that the setting is replicated too. This is only likely to be an issue if the setting is in the Data Access level as that's the one most likely to get changed (different database provider for example).

ChrisF
A: 

Never actually done this, but in theory it might work...

When you define your custom configuration section, set its configSource to an external file (whatever.config). This external file should be added to the SOLUTION and not the project. It will appear under "Solution Items". In each project, Add an Existing File, browse to whatever.config, click the dropdown on the Add button and select "Add as Link."

Whatever.config will be a single file you can edit under Solution Items, and it gets copied into each application at compile time.

Will
Yea I was thinking on the same lines. The only issue I have is that I wanted to have the handler class (which parses the information from whatever.config) to be as a solution item as well. so that the config + its parser are existing only once and are being linked into multiple projects. Though the issue is not that will visual studio compile a class which is at Solution Item level? I haven't been able to do it.
nEEbz