是否可以配置Azure C#函数DocumentDB属性参数? [英] Is it possible to configure Azure C# function DocumentDB attribute arguments?
问题描述
我正在构建一个Azure Http触发的C#函数,并将其输出绑定到Cosmos DB.我的函数定义是这样的:
I'm building an Azure Http triggered C# function with an output binding to Cosmos DB. My function definition is like this:
[FunctionName("HttpTriggerFunction")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = "myroute")]HttpRequestMessage req,
[DocumentDB("database", "collection", ConnectionStringSetting = "CosmosDBConnection")] IAsyncCollector<dynamic> document,
TraceWriter log)
这很好.
但是,我希望能够在DocumentDB属性中配置数据库和 collection 名称,但是如果尝试以下操作:
However, I would like to be able to configure the database and collection names in the DocumentDB attribute, but if I try something like:
[DocumentDB(ConfigurationManager.AppSettings["DatabaseName"], ConfigurationManager.AppSettings["CollectionName"], ConnectionStringSetting = "CosmosDBConnection")]
然后Visual Studio给我一个编译错误:
then Visual Studio gives me a compilation error:
CS0182属性参数必须是属性参数类型的常量表达式,typeof表达式或数组创建表达式
有什么方法可以配置这些DocumentDB属性参数?
Is there any way to configure these DocumentDB attribute arguments?
推荐答案
您需要执行以下操作:
[DocumentDB("%database%", "%collection%", ConnectionStringSetting = "CosmosDBConnection")]
,然后定义具有相应名称的设置(不包含%
).
and then define settings with corresponding names (without %
).
这篇关于是否可以配置Azure C#函数DocumentDB属性参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!