【发布时间】:2020-08-26 20:05:24
【问题描述】:
我制作了一个连接到 CosmosDB 的 Azure Functions 应用。我创建了以下类来检索CosmosClient 实例:
public static class CosmosClientContext
{
private static readonly CosmosClient CosmosClient = GetCosmosClient();
public static CosmosClient GetCosmosClient()
{
return CosmosClient
//?? new CosmosClient("AccountEndpoint=https://mycosmosdb.documents.azure.com:443/;AccountKey=JkLv....etc;");
?? new CosmosClient("AccountEndpoint=https://localhost:8081/;AccountKey=C2y6...etc");
}
}
如您所见,我目前在课堂上对ConnectionString 进行硬编码,这显然不是最优的。
我注意到我的项目中有一个local.settings.json 文件。那是存储到本地连接字符串的地方吗?如果是这样,我是否必须为此使用特定的键名?或者我如何从中读取?
当我发布我的 Azure Functions 应用程序时,它是如何工作的?
那么我怎样才能让它在本地使用我的本地ConnectionString,并在发布时自动使用远程ConnectionString?
【问题讨论】:
标签: azure azure-functions azure-cosmosdb