Today I spent some time working on DynamicConfig , I had some minor/major refactorings in mind and also a couple of features I wanted to add.
Probably the most important update is the possibility now to save the configurations to file, operation performed directly by the library when a property changes. At the moment this feature is available only when a configuration was previously loaded from file, but I plan to extend this.
In a nutshell, all you have to do is load a configuration from file:
|var filename = "config.json";|
|var providerName = "json";|
|var configName = "myConfig";|
|dynamic config = Config.Load(providerName, configName, filename);|
and then just update a property, the library will do the rest 🙂
Internally what is happening is that the configuration class ( ConfigObject ) now implements the IObservable<> interface, so whenever a change occurs the registered observers will get a notification. The JsonConfigProvider instead implements IObserver<> and subscribes to the events during file loading.
A quick description to the Observer pattern can be found on CodeProject here ( although the pattern is very well know and I am sure doesn’t require introduction ). The idea is to maintain a list of objects that will be notified by the observer each time a specific event occurs on the observed class itself.
On the ConfigObject class I also added a Parent property so that each message will be sent also to its subscribers.
Now I just have to add a couple of error checks and push the build to NuGet 🙂