0
votes

Currently, by default, Azure function base path is set to "D:\home\site\wwwroot". For example, when publishing, VS uploads app to this folder.

I need to read config file from this folder. We have problem of ExecutionContext is null via dependency injection via constructor

Setting a new environment variable might cause issue if the path is changed in the future.

My question is that how can I use app base path that is reliable and stable, that works with DI via constructor.

Azure Function 2.x

VS 2017

2

2 Answers

0
votes

There is an environment variable pointing to home directory. This would not change as many services including function app take dependency on it. Below is how function runtime fetches it in azure environment.

    string home = GetEnvironmentVariable("HOME");
    Path = System.IO.Path.Combine(home, "site", "wwwroot");
1
votes

you can use function.json to have your configuration key pairs. for example:

System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);

and in function.json you can do like this: "mykey": "myvalue"

{
  "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.24",
  "configurationSource": "attributes",
  "bindings": [
  {
      "direction":"in",
      "type": "timerTrigger",
      "useMonitor": true,
      "runOnStartup": false,
      "name": "myTimer",
      "mykey": "myvalue"
  }
  ],
      "disabled": false,
      "scriptFile": "../bin/**.dll",
      "entryPoint": "**.Run"
}