All Projects → spadger → Simple Config

spadger / Simple Config

Licence: lgpl-3.0
A .Net convention-based config to object binder

Projects that are alternatives of or similar to Simple Config

Go Config
A dynamic config framework
Stars: ✭ 595 (+1508.11%)
Mutual labels:  config, configuration
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+1951.35%)
Mutual labels:  config, configuration
Konfig
Composable, observable and performant config handling for Go for the distributed processing era
Stars: ✭ 597 (+1513.51%)
Mutual labels:  config, configuration
Koanf
Light weight, extensible configuration management library for Go. Built in support for JSON, TOML, YAML, env, command line, file, S3 etc. Alternative to viper.
Stars: ✭ 450 (+1116.22%)
Mutual labels:  config, configuration
Configuron
Clojure(Script) config that reloads from project.clj when in dev mode
Stars: ✭ 24 (-35.14%)
Mutual labels:  config, configuration
Easy Wg Quick
Creates Wireguard configuration for hub and peers with ease
Stars: ✭ 502 (+1256.76%)
Mutual labels:  config, configuration
Ini Parser
Read/Write an INI file the easy way!
Stars: ✭ 643 (+1637.84%)
Mutual labels:  config, configuration
Hoplite
A boilerplate-free library for loading configuration files as data classes in Kotlin
Stars: ✭ 322 (+770.27%)
Mutual labels:  config, configuration
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+2372.97%)
Mutual labels:  config, configuration
Strictyaml
Type-safe YAML parser and validator.
Stars: ✭ 836 (+2159.46%)
Mutual labels:  config, configuration
Centraldogma
Highly-available version-controlled service configuration repository based on Git, ZooKeeper and HTTP/2
Stars: ✭ 378 (+921.62%)
Mutual labels:  config, configuration
Lilconfig
Zero-dependency nodejs config seeker.
Stars: ✭ 35 (-5.41%)
Mutual labels:  config, configuration
V2ray Step By Step
This repo is a fork of ToutyRater/v2ray-guide, we aim to provide a new step-by-step guide of v2ray
Stars: ✭ 341 (+821.62%)
Mutual labels:  config, configuration
Jsonnet
Jsonnet - The data templating language
Stars: ✭ 5,257 (+14108.11%)
Mutual labels:  config, configuration
Config
The Config component helps you find, load, combine, autofill and validate configuration values of any kind, whatever their source may be (YAML, XML, INI files, or for instance a database).
Stars: ✭ 3,671 (+9821.62%)
Mutual labels:  config, configuration
Xxl Conf
A lightweight distributed configuration management platform. (分布式配置管理平台XXL-CONF)
Stars: ✭ 619 (+1572.97%)
Mutual labels:  config, configuration
Charles-Proxy-Mobile-Guide
The mobile hackers' guide to Charles Proxy 👍
Stars: ✭ 105 (+183.78%)
Mutual labels:  config, configuration
goconfig
.gitconfig syntax parser
Stars: ✭ 15 (-59.46%)
Mutual labels:  config, configuration
V2ray Examples
v2ray-core 的模板们
Stars: ✭ 778 (+2002.7%)
Mutual labels:  config, configuration
Configuration
Library for setting values to structs' fields from env, flags, files or default tag
Stars: ✭ 37 (+0%)
Mutual labels:  config, configuration

simple-config

Simple-config is an extensible, convention-based XML to C# binder, specifically designed to easily bind custom config sections without the need to write any config handlers or sections.

Simply by performing a cast to the required type, SimpleConfig will perform all required mapping, without the use for any magical markup.

Nuget Nuget Build status

##Simple use case

If we have some configurable settings

public class ServiceSettings
{
  public int MaxThreads { get; set; }
  public string Endpoint { get; set; }
  public IEnumerable<string> BannedPhrases { get; set; }
}

we could write the xml for it in our app.config or web.config

<!-- Wire up the handler inside the <configSections /> element; once per custom section -->
<section name="serviceSettings" type="SimpleConfig.SimpleConfigHandler, SimpleConfig" />

<!-- And this goes in the main part of the config file -->
<serviceSettings maxThreads="4">
  <endpoint>http://localhost:9090</endpoint>
  <bannedPhrases>
    <phrase>something</phrase>
    <phrase>else</phrase>
  </bannedPhrases>
</serviceSettings>

We could now write a disproportionately large ConfigurationSection, or a some boilerplate code, or we could just call this:

var settings = (ServiceSettings)(dynamic)ConfigurationManager.GetSection("serviceSettings");

or even

ServiceSettings settings = (dynamic)ConfigurationManager.GetSection("serviceSettings");

##Binding to interfaces As of version 1.2 (Nov 2014), it is possible to bind to a pure interface (a concrete class will be create for you). The binding copes with subinterfaces and multiple inheritence too; you just need to remember the following points:

* Your interface cannot define any methods
* Each property must define a getter (setters are optional)
* You must use implicit binding to invoke the mapper:
IServiceSettings settings = (dynamic)ConfigurationManager.GetSection("serviceSettings");

##Overriding the default conventions If you don't mind using attributes, Simple-config does come with some a small selection of binding hints to guide the binding process. For example, using the same xml as above, the following settings DTO could still be bound:

public class ServiceSettings
{
  public int MaxThreads { get; set; }
  public string Endpoint { get; set; }
  
  [CustomEnumerable("bannedPhrases")]  //magic
  public IEnumerable<string> PhrasesThatAreBanned { get; set; }
}

##Enumerables and lists Simple-config is designed to be helpful when binding IEnumerables; please consider the following when binding:

  • You destination needs to implement System.Collections.Generic.IEnumerable<> so that the payload type is known
  • You can only bind to IEnumerable<> if the destination property has a setter (so SimpleConfig can create a mutatable Type)
  • If your destination property has no setter, it needs to be pre-populated with something that implements ICollection<>

##Do anything

The architecture of Simple-config allows you to create new binding strategies to perform whatever custom binding you need, for example, to decrypt sensitive config

Simply create a binding stratgy that implements IBindingStrategy

/// <summary>
/// Details a specific strategy for populating an object based on the config
/// </summary>
public interface IBindingStrategy
{
    /// <param name="destinationObject">The instance of the object ot be populated</param>
    /// <param name="destinationProperty">The property to be populated</param>
    /// <param name="element">The config element at the level we are mapping</param>
    /// <param name="allConfig">The entire config dom, as provided to the config handler</param>
    /// <param name="mapper">The current config mapper</param>
    /// <returns>Whether or not the binding was successful</returns>
    bool Map(object destinationObject, PropertyInfo destinationProperty, XmlElement element, XmlElement allConfig, ConfigMapper mapper);
}

In order to hook up the binding strategy, create a new binding attribte that inherits BaseBindingAttribute

[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
public abstract class BaseBindingAttribute : Attribute
{
    public abstract IBindingStrategy MappingStrategy { get; }
}

Then attach the binding attribute to the property that requires custom binding.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].