Coder Social home page Coder Social logo

azurefunctions.aspnetconfiguration's Introduction

AzureFunctions.AspNetConfiguration

Adds ASP.NET Core Configuration capabilities to Azure Functions

Azure Functions typically relies on local.settings.json and Azure environment variables for appsettings. If you are here, you want an experience similar to ASP.NET.

Build Status

Nuget

Configure

To configure this plugin, add a NuGet reference to AzureFunctions.AspNetConfiguration and then add builder.UseAspNetConfiguration() to Startup.cs, like:

using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using YellowCounter.AzureFunctions.AspNetConfiguration;

[assembly: FunctionsStartup(typeof(SampleFunctionApp.Startup))]
namespace SampleFunctionApp
{
    public class Startup : FunctionsStartup
    {
        public override void Configure(IFunctionsHostBuilder builder)
        {
            builder.UseAspNetConfiguration();
        }
    }
}

Complex objects

Unlike local.settings.json, appsettings.json supports complex/sectioned settings such as

{
  "section": {
    "hello": "world"
  },
}

They are retrieved via standard means, as one would expect.

Configuration Hierarchy

The configuration added ASP.NET configuration on top of the default Azure Functions configuration settings. So we get this hierarchy:

  1. local.settings.json (by default)
  2. Environment variables (by default)
  3. appsettings.json
  4. appsettings.{EnvironmentName}.json
  • EnvironmentName is pulled from the value if AZURE_FUNCTIONS_ENVIRONMENT
    • In Visual Studio, this value defaults to 'Development'
    • In Azure, this value defaults to 'Production'
    • I'm following up to determine how to best override this value locally.
    • You can override using ASPNETCORE_ENVIRONMENT, but it is not recommended
  1. User Secrets, if AZURE_FUNCTIONS_ENVIRONMENT is set to 'Development'
  2. Environment variables (again, to give it the highest priority)

Extend

If you would like to use other ASP.NET config providers, you can add others to the end (and thus give them highest priority), for example:

var settings = new Dictionary<string, string>
{
    { "setting5", "memory" }
};
builder.UseAspNetConfiguration(c => c.AddInMemoryCollection(settings).AddEnvironmentVariables());

Retrieve configuration

In order to retrieve the configuration settings themselves, you can use:

var configuration = builder.GetConfiguration();
var value = configuration["setting1"];

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.