Giter Site home page Giter Site logo

mgkconfigurationmanager's Introduction

MGKConfigurationManager

Simple configuration manager for settings and secrets in .NET

MGKConfigurationManager is a simple .NET library for pulling in per-project and solution-wide secrets and solution-wide settings when developing locally. (Per-project settings will be in web.config as normal.) When running in a hosted environment (e.g. Microsoft Azure) settings and secrets would typically be stored in an app configuration settings store or a dedicated key vault.

All settings and secrets are stored outside the project working directory so as not to be checked into source control.

MGKConfigurationManager imports all settings and secrets into a single, flat namespace implemented as a .NET NameValueCollection. As a result key names must be unique across all config files. MGKConfigurationManager uses the .NET configuration management classes so it will grab secrets and settings whether they're defined in local config files, server-based config files or in the Azure App Service Application Settings blade.

MGKConfigurationManager has no error or exception handling.

Configuration:

Place the following in the <configSections> element of your web.config file in each project within a given solution:

<configSections>
  <section name="LocalSecrets" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <section name="GlobalSecrets" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <section name="GlobalSettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</configSections>

Place the following directly under the <configuration> element of your web.config file in each project within a given solution:

<LocalSecrets file="..\..\{SOLUTION_NAME}.Settings\{PROJECT_NAME}\localsecrets.config"></LocalSecrets>
<GlobalSecrets file="..\..\{SOLUTION_NAME}.Settings\globalsecrets.config"></GlobalSecrets>
<GlobalSettings file="..\..\{SOLUTION_NAME}.Settings\globalsettings.config"></GlobalSettings>

where:

  • {SOLUTION_NAME} is the name of your overall solution
  • {PROJECT_NAME} is the name of the project where the web.config file resides

localsecrets.config, globalsecrets.config and globalsettings.config look as follows:

localsecrets.config:

<LocalSecrets>
  <add key="key1" value="value1" />
  <add key="key2" value="value2" />
</LocalSecrets>

globalsecrets.config:

<GlobalSecrets>
  <add key="key1" value="value1" />
  <add key="key2" value="value2" />
</GlobalSecrets>

globalsettings.config:

<GlobalSettings>
  <add key="key1" value="value1" />
  <add key="key2" value="value2" />
</GlobalSettings>

Sample directory structure:

\My_solution_dir
  \Project1
    web.config
  \Project2
    web.config
  \Project3
  My_solution.sln
\My_solution.Settings
  globalsecrets.config
  globalsettings.config
  \Project1
    localsecrets.config
  \Project2
    localsecrets.config
  \Project3
    localsecrets.config

Usage:

Bootstrap MGKConfigurationManager as follows - when your app starts (entry point will depend on project type), create a static instance of MGKConfigurationManager passing an array of custom section names as shown above.

static MGKConfigurationManager settings = new MGKConfigurationManager(new string[] { "LocalSecrets", "GlobalSecrets", "GlobalSettings" });

MGKConfigurationManager imports all settings and secrets - regardless of the source as stated above - into a single, flat namespace. Key name uniqueness is a requirement. Values are retrieved as follows:

settings.AppSettings["My_setting_or_secret_name"]);

Requests for non-existent key names return an empty string.

mgkconfigurationmanager's People

Contributors

matthewkrieger avatar

Watchers

 avatar

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.