Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do hierarchical configuration in .NET's app.config

app.config configuration sections are nice, but I often need multiple configuration sets, but with small difference. what I want is:

  1. Have one section with default configuration (this one is created with the designer, and thus has the auto-generated strongly-typed accessors in the Settings class
  2. Another section with only the "new" items, and all other items get their values from the original section.

(note - it is also would be nice to place that "other section" in a separate file, but this is a different issue.)

Edit: the application is plain executable (or a service) - it is not a web service. Also, I know there is a "machine.config" to inherit from, but its too global: its for all apps together

like image 502
user19871 Avatar asked Nov 13 '08 20:11

user19871


People also ask

What is the difference between web config and app config?

The web. config file is required for ASP.NET webpages. The app. config file is optional in an application and doesn't have to be used when writing desktop applications.

Where is the configuration stored in each Framework?

Machine configuration files This file is located in the %runtime install path%\Config directory.


1 Answers

I think you'd have to use a custom handler to manage this.

The second part is easy as you can use an configSource Attribute in the original config file to point to a file that contains the xml source.

<system.serviceModel>
    <diagnostics>
      <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true"
        logMessagesAtTransportLevel="true" />
    </diagnostics>
    <bindings configSource="web.shared.bindings.config" ></bindings>
    <client configSource="web.shared.client.config" ></client>    
</system.serviceModel>

Here is how we link parts of the Service.ServiceModel XML into our Web Config so we can keep them seperate and easily edited.

like image 86
Brody Avatar answered Oct 13 '22 12:10

Brody