Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mizrael/dynamicconfig
https://github.com/mizrael/dynamicconfig
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/mizrael/dynamicconfig
- Owner: mizrael
- License: gpl-2.0
- Created: 2015-05-28T14:25:08.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-06-08T07:21:16.000Z (over 9 years ago)
- Last Synced: 2024-10-04T15:15:51.264Z (about 2 months ago)
- Language: C#
- Size: 184 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DynamicConfig README
=====================## About
DynamicConfig is a very simple to use configuration library based on the C# 4.0 dynamic feature. It allows loading from file (or parsing) multiple configurations that can be later accessed via dynamic typing, no custom classes or casts are required.
If a configuration was loaded from file, updating a property will result in the original file to be updated.DynamicConfig is somewhat based on JsonConfig ( https://github.com/Dynalon/JsonConfig ) but uses Newtonsoft.JSON instead of JsonFX
## Examples
The main entry-point of the library is the DynamicConfig.Config class from which you can access all the exposed functionalities.
The first thing to do is to register a provider, at the moment there is a JsonConfigProvider included, so:```csharp
var provider = new Providers.JsonConfigProvider();
Config.RegisterProvider("json", provider);
```Providers can be retrieved using the GetProvider method:
```csharp
var jsonProvider = Config.GetProvider("json");
```### Loading data
Then you can load a configuration from file directly via the DynamicConfig.Config class
```csharp
var providerName = "json";
var configName = "myConfig";
dynamic config = Config.Load(providerName, configName, filename);
```or via the Provider:
```csharp
var jsonProvider = Config.GetProvider("json");
var configName = "myConfig";
dynamic config = jsonProvider.Load(configName, filename);
```configurations can be accessed using dynamic typing on the Provider:
### Accessing data
```csharp
var jsonProvider = Config.GetProvider("json");
var foo = jsonProvider.myConfig.foo;
Console.Writeline("foo: {0}", foo);
```### Nesting
configurations can include also complex objects:
```csharp
var json = "{name:\"John\", complex:{ one: 1, two: 2, three: \"three\" } }";
var jsonProvider = Config.GetProvider("json");
var configName = "myConfig";
jsonProvider.Parse(configName, json);
var three = jsonProvider.myConfig.complex.three;
Console.Writeline("three: {0}", three);
```## Incoming Features/Upgrades
- monitor config file changes on filesystem to force config reload
- provider options (eg. readonly)
- Async
- appSettings Provider## TODO
- better error checking (eg. while saving)
-