1
votes

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)

This works fine.

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")]

then Visual Studio gives me a compilation error:

CS0182 An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

Is there any way to configure these DocumentDB attribute arguments?

1

1 Answers

9
votes

You need to do this:

[DocumentDB("%database%", "%collection%", ConnectionStringSetting = "CosmosDBConnection")] 

and then define settings with corresponding names (without %).