POST POST

OCT
5
2021

Configuration in Azure Isolated Functions

ORIGINALLY POSTED TO: https://blog.simontimms.com/2021/10/05/azure-isolated-functions-config

This is all done in the Program.cs. If you want to use the IOptions pattern which, let's face it, everybody does. Then you can start with creating your configuration classes (I like more than one so config for different parts of the app remain logical distinct). These are POCOs

1
2
3
4
5
6
7
8
public class AuthConfiguration
{

public string TenantId { get; set; }
public string ClientId { get; set; }
public string ClientSecret { get; set; }
public string RedirectUrl { get; set; }
}

Then set this up in the host builder

1
2
3
4
5
6
7
8
9
10
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureServices(container =>
{
container.AddOptions<AuthConfiguration>().Configure<IConfiguration>((settings, config) =>
{
config.Bind(settings);
});
})
.Build();

If this looks familiar it's because it totally is! All of this uses the generic .NET host so this same sort of pattern should work in most .NET apps now.


Simon Timms

Email Email
Web Web
Twitter Twitter
GitHub GitHub
RSS

Looking for someone else?

You can find the rest of the Western Devs Crew here.

© 2015 Western Devs. All Rights Reserved. Design by Karen Chudobiak, Graphic Designer