Giter Site home page Giter Site logo

configgy's Introduction

Configgy

Configgy: The Last Configuration Library for .NET

A simple, powerful, extensible, testable .NET configuration library.

Build Status NuGet Version

Documentation

README

  1. Overview
    1. Cache
    2. Source
    3. Transform
    4. Validate
    5. Coerce
  2. Other Features
  3. Advanced Usage

Description

Configgy is the last .NET configuration library you'll ever need. It is designed to support configuration values coming from any source, with any kind of validation, and then expose it all as strong types - even complex types like lists, dictionaries, or general .NET objects.

Usage

The simplest usage of Configgy is to inherit from Configgy.Config and add the configuration properties you want like this:

using System;
using Configgy;

public class MyConfig: Config, IMyConfig
{   
    [DefaultValue(100)] //assign a default value.
    public int MaxThingCount { get { return Get<int>(); } }
    [DefaultValue("Server=server;Database=db;User Id=usr;Password=pwd;")] //assign a default value.
    public string DatabaseConectionString { get { return Get<string>(); } }        
    public DateTime WhenToShutdown { get { return Get<DateTime>(); } }
    
    //use expression bodied statements
    public int MinThingCount => Get<int>();
}

Installation

You can build from this source or you can get it from nuget here: https://www.nuget.org/packages/Configgy

Design

The basic design of Configgy boils down to a few key points:

  • Get configuration values from anywhere. (Easily extensible configuration sources.)
  • Transform raw values before validation or coercion. (Easily extensible value transformers.)
  • Validate any configuration value in any way. (Easily extensible configuration validators.)
  • Support any strongly typed configuration value, including complex objects! (Easily extensible configuration type coercers.)
  • Test all the things! (Modular/testable design. Current unit test coverage above 90%)

Features

Here are a bunch of things supported by Configgy out of the box:

  • Strongly typed configuration properties including complex objects
    • Any value type you can imagine including enums, numerics, DateTime, TimeSpan and strings
    • JSON for complex objects (preferred)
    • XML for complex objects (not recommended but it works)
  • Configuration sources
    • Command line switches (trust me this bit is swanky)
    • Environment variables
    • Files (named like the conf value you're looking for)
    • Net Core appsettings.json files
    • Connection string entries in a web/app config
    • App setting entries in a web/app config
    • Embedded resources (just like the files above but embedded in the app)
    • System.ComponentModel.DefaultValueAttribute
  • Value transformers
    • Convert encrypted strings (RSA encrypted then base-64 encoded) into plaintext.
    • Convert relative paths to absolute ones
    • Convert strings to upper or lower case
  • Validation
    • Automatic validation for all numeric types, DateTime, TimeSpan
    • Validation of any numeric, DateTime, or TimeSpan configuration properties by min/max or valid value arrays
    • Validation of any configuration property by regular expression
  • Caching
    • In-memory caching of post-coercion values to reduce reflection by default and make most config value lookups lightning fast
  • Optional preemptive validation - know that a config value is bad when your app starts up (or any other time you choose) instead of hours or days later when you get some inscrutable null reference exception or an unexplained int.Parse error.
  • Populate any configuration object even ones provided by thridparty libraries using the same Configgy.ConfigProvider instance - so just configure it once
  • Dependency Injection - an interface for everything and everything has an interface. You can assemble an entire Configgy.ConfigProvider instance with DI if you wish

Extensibility

Here are a bunch of things that are really easy to do because of the Configgy design

  • Encrypt sensitive settings such as api keys, connection strings, passwords, etc.
  • Pull your configuration values from any database, web service or other source you can imagine.
  • Add your own validators to prevent/allow only certain enum values, strings, or complex object values.
  • Write your own value source to change the command line configuration option syntax if you don't like the kick-ass one I came up with.
  • Cache your config values to somewhere besides memory, maybe Redis or MemCached, or an instance of System.Runtime.Caching.MemoryCache.
  • Coerce values into the wrong types to annoy your coworkers!

Bugs And Feature Requests

Any TODO items, feature requests, bugs, etc. will be tracked as GitHub issues here: https://github.com/bungeemonkee/Configgy/issues

Thanks

Thanks to Alex Bielen for the awesome logo!

configgy's People

Contributors

bungeemonkee avatar wjdavis5 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

configgy's Issues

Problem Reading in Array of String

Put this in json file

"Dogs": [ "St. Bernard"]

Tried these in Config

List<string> Dogs { get; set; }

string[] Dogs { get; set; }

public IEnumerable<string> Dogs { get; set; } = null!;

[Configgy.Coercion.CsvCoercerAttribute(typeof(string))] public string[] Dogs { get; set; }

but all error out

Support Persisting Values

Create a mechanism for saving changed values back to the persistence mechanism they came from.

Default to saving them to the source they came from, but ad an attribute to allow them to be saved to any specific source.

Support settings from embedded resources

Could be useful for embedded binary info like images or for large text blobs. Might work something like the file source. Would probably be best to look (by default) in a predetermined namespace like "Resources.Settings". Should it scan all assemblies or just the entry assembly?

3.x-rc does not install into 4.5.2 targeted project

When trying to install the latest 3.x RC version of Configgy into a console app targeting .net 4.5.2 the following error occurs

Could not install package 'Configgy 3.0.2-rc3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.2', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.			

when trying to do the same with 2.x the install works fine

Allow encryption of long strings

Currently we RSA encrypt the whole setting value. This forces settings to be small. We should AES encrypt the setting the RSA encrypt the key.

Encryption Utility

Create a small WPF and/or command line utility to encrypt config values using the same logic as the decryption in Configgy.

Support NetStandard

Ideally version 1.4 maybe version 1.6. There are some sources that may be .NET Framework specific and may need to be pulled into a separate project.

Attribute and extension method to generate command-line help

Create an attribute (something like [Help(string)]) that can be used to get documentation about each config option.

Then add an extension method (GetCommandLineHelp() perhaps) which enumerates these values and generates each in the command line format of the option ('--XXXXX') with it's help text.

If the option is excluded from the command line source (see #12) it should be excluded.

If the option has no help text it should be included by default but there should be an option to exclude these.

Ideally the method would be able to intelligently wrap the output to a given width (perhaps as a parameter). If the app is running in a user mode (Environment.UserInteractive is true) it should default to the current console width (Console.WindowWidth). If the app is not running in a user interactive mode it should default to a predetermined number (probably 80).

Namespace cleanup

Change the Transformers namespace to be Transformation to be just a little bit more consistent.

Create links to types in docs

The documentation references a lot of types. Types inside the Configgy library should have links that reference the source files. Types from the .NET system files should have links that reference the corresponding MSDN pages for those types.

Documentation Update

The documentation should be restructured so that the readme points to documentation structured with an overview of the pipeline followed by a description of each step in the pipeline, then followed by advanced topics like database sources, use with dependency injection, etc.

Overall sections would be:

  • README
  • Pipeline Overview
  • Sources
  • Transformers (to be implemented in v1.1)
  • Validators
  • Coercers
  • Caching
  • Advanced

Use --XXXXXXX Command Line Format

Add a dashed command line source to include options in the form of '--[Property Name]=[Value]'. This shouldn't be made the default behavior though to preserve backwards compatibility.

Generic object source

Add a source to pull values from any object's fields/properties. Could be really useful when needing to inter-operate with other configuration sources/systems without needing direct dependencies on them.

Add an attribute to prevent certain values coming from certain sources

Something like [PreventSource(typeof(CommandLineSource))] would be really useful for ensuring that key values only come from certain sources. The AggregateSource class would then need to enforce this. In this way we could prevent sensitive values such as connection strings from being overwritten on the command line.

Smart Card?

Trying to run test in VS2017 and it keeps asking me to connect a smart card. Any idea what that's about?
Looks like its the Encrypt_With_No_Private_Key_Then_Decrypt_Throws_InvalidOperationException test method

I couldnt even cancel the test. Had to plug in my yubikey and input my pin for this to go away.

image

Support RequiredAttribute

I'm going to start working on this for my apps. But wanted to see what you thought about adding support for the RequiredAttribute. When the config class gets initialized verify all properties decorated as required evaluate to a valid value, and if not bubble up the exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.