views:

27

answers:

1

I am working on a web app that will heavily rely on configuration. The configuration is also will be written by another process or human. I am looking to get response on best practices in .net 3.5 on how to implement this case. I had used the configuration section of an early version of the Enterprise Library Applications Block. I really liked working with it but from what I hear it is discontinued in current versions. Hence the question...

Need to be able to serialize collections, pick up file write event to reload new instance of config into memory.

Thank you.

A: 

Have you looked at the System.Configuration namespace? It's relatively painless to create ConfigurationSection, ConfigurationElement and ConfigurationElementCollection instances. Those 4 Guys from Rolla have blogged about it, and there are plenty of tutorials using that whole "google" thing.

One thing to note with this approach, is that when you make a change to a web.config, the application is automatically recycled for you.#

UPDATE You can in fact separate you configuration into separate .config files. You still need to declare the <section> and <sectionGroup> elements in your master web.config file, but any config section that inherits from ConfigurationSection supports a configSource property. E.g.:

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
  <configSections>
    <section name="myConfigSection" type="..." />
  </configSections>

  <myConfigSection configSource="myConfigSection.config" />
</configuration>

And then you can add a separate myConfigSection.config file:

<?xml version="1.0" encoding="UTF-8" ?>
<myConfigSection>
  <someElement />
</myConfigSection>
Matthew Abbott
Yes, I have looked at it - it is rather simple to write your own settings to web.config. The whole problem is that I would like to keep my settings in separate stand alone xml files. One xml file per custom config section. I gather that I will have to write my own provider for it...Dont want my app to reaload each time there is a change.
Max Malygin
I've updated my answer to include how to separate your configs into separate files. I'm not sure how to get around the restart scenario, it's a design feature of ASP.NET applications.
Matthew Abbott
I'm not sure about it, but maybe you can add a FileSystemWatcher to monitorize changes on files on Application start.
Elph
I would imagine you could do that, but I would be hesitant to try and re-invent the wheel.
Matthew Abbott
Thank you so much!
Max Malygin