Giter VIP home page Giter VIP logo

winton.extensions.configuration.consul's Introduction

Winton.Extensions.Configuration.Consul

Build status Travis Build Status NuGet version NuGet version

Adds support for configuring .Net Core application using Consul. It is expected that the configuration will be stored as a single object under a given key in Consul. Works great with git2consul.

Installation

Add Winton.Extensions.Configuration.Consul to the dependencies section of your project.json

Usage

Add the following to your StartUp class for the minimal setup:

var cancellationTokenSource = new cancellationTokenSource();
var builder = new ConfigurationBuilder()
    .AddConsul(
        $"{env.ApplicationName}.{env.EnvironmentName}",
        cancellationTokenSource.Token);
Configuration = builder.Build();

Assuming the application is running in the development environment and the application name is Website, this will load a json configuration object from the key Website/Development in Consul.

The CancellationToken is used to cancel any current requests or watches with Consul. It is recommended that this is cancelled during application shut down to clean up resources. This can be done like so in the Configure method of your StartUp class by injecting the IApplicationLifetime:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, IApplicationLifetime appLifetime)
{
    // Other app configuration

    appLifetime.ApplicationStopping.Register(_cancellationTokenSource.Cancel);
}

An options Action can be specified as a third argument to set the options outlined below.

Configuration Options

  • ConsulConfigurationOptions

    An Action that can be used to configure Consul options

  • ConsulHttpClientOptions

    An Action that can be used to configure Consul HTTP options

  • ConsulHttpClientHandlerOptions

    An Action that can be used to configure Consul HTTP handler options

  • OnLoadException

    An Action that can be used to configure how exceptions should be handled during load

  • OnLoadException

    An Action that can be used to configure how exceptions should be handled that are thrown when watching for changes

  • Optional

    A bool that indicates whether the config is optional. If false then will throw during load if the config is missing for the given key.

  • Parser

    The parser to use, should match the format of the configuration stored in Consul. Defaults to JsonConfigurationParser. Either use those under Winton.Extensions.Configuration.Consul.Parsers or create your own by implementing IConfigurationParser.

  • ReloadOnChange

    A bool indicating whether to reload the config when it changes in Consul. If true it will watch the configured key for changes and then reload the config asynchronously and trigger the IChangeToken to raise the event that the config has been reloaded.

Backlog

  • Add more parsers for different file formats
  • Add support for expanded configuration where the configuration is a tree of KV pairs under the root key

winton.extensions.configuration.consul's People

Contributors

ah- avatar choc13 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.