Get configuration while wiring dependency injection in Function App

473 Views Asked by At

We used this blog post https://blog.mexia.com.au/dependency-injections-on-azure-functions-v2 to set up dependencies in our Function App project.

DI part works fine, however, some classes require configuration settings. In DiModule we have the following code:

  var configuration = new ConfigurationBuilder()
                .SetBasePath(Environment.CurrentDirectory)
                .AddJsonFile("serilog.json")
                .Build();

Environment.CurrentDirectory works on local machine, but doesn't work in Azure. I know that working implementation is

.SetBasePath(context.FunctionAppDirectory)

where context is of type ExecutionContext. Is there a way to get ExecutionContext except from function parameter?

Or is there better way to load config in Function App (without loading it from every function call)?

1

There are 1 best solutions below

0
On BEST ANSWER

We end up using 2 kinds of settings with Azure Functions: 1. App settings 2. Custom settings stored in the database with a cache layer

Serilog settings are stored in app settings.