Azure功能如何将应用程序设置添加到绑定

Mer*_*roz 11 c# settings binding azure azure-functions

我正在尝试使用我的Azure功能的应用程序设置添加一些自定义绑定.我需要从我的设置中只收到一个字符串.

在此输入图像描述

我想从我的设置中获得simpleValue.

{
   "bindings": [
    {
      "name": "someValue",
      "type": "stringSetting",
      "connection": "simpleValue",
      "direction": "in"
    }
  ],
  "disabled": false
}
Run Code Online (Sandbox Code Playgroud)

并在Run方法中获取它:

static void GetOrders(TraceWriter log, string someValue)
{
    log.Info(someValue);
}
Run Code Online (Sandbox Code Playgroud)

它甚至可能吗?也许有其他方法可以做到这一点?

Mer*_*roz 21

我已经找到了解决方案.只需添加:

using System.Configuration;
Run Code Online (Sandbox Code Playgroud)

并使用键("simpleValue")值将此行添加到代码中:

ConfigurationManager.AppSettings["simpleValue"]
Run Code Online (Sandbox Code Playgroud)

  • 它不是`ConfigurationManager.AppSettings ["bindings:connection"]`而是? (3认同)

Rim*_*ima 5

应用设置配置可以在绑定 json 中引用为 %MY_CUSTOM_CONFIG% - 包含在百分比符号中。

请注意,触发器和绑定的连接属性是一种特殊情况,它会自动将值解析为应用程序设置,没有百分号。 https://docs.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings