Skip to content

MarkDaviesEsendex/Azure-Useful-Bindings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure-Useful-Bindings

A repository of useful bindings - maybe

What is this

Hopefully a collection of useful bindings for Azure functions

Build status

Bindings

From Config

Sometimes I just want to grab one or maybe two config settings from the local.settings.json but that means that I have to use Environment.GetEnvironmentVariable which immediately throws up alarm bells for me! It makes tests so much harder to write and a lot more secrative because somewhere in my test I now have to use Environment.SetEnvironmentVariable which I hate doing because it creates flakey tests - most test runners don't clear down environment variables which means that I now have to run tests syncronously. That's a massive headache just for one config value in a function!

Introducing FromConfig

String

public static class Function
{
    [FunctionName("Function")]
    public static void Run([FromConfig(Name = "ConfigSettingName")] string configValue)
    {
    }
}

Int

public static class Function
{
    [FunctionName("Function")]
    public static void Run([FromConfig(Name = "ConfigSettingName")] int configValue)
    {
    }
}

Uris

public static class Function
{
    [FunctionName("Function")]
    public static void Run([FromConfig(Name = "ConfigSettingName")] Uri configValue)
    {
    }
}

Bools

public static class Function
{
    [FunctionName("Function")]
    public static void Run([FromConfig(Name = "ConfigSettingName")] bool configValue)
    {
    }
}

Easy to use, it will take the setting name and bind it to a string value, I may extend this in future to do more types i.e. UriFromConfig, if there is enough interest.

Releases

No releases published

Packages

No packages published

Languages