gpt4 book ai didi

azure - 单例 Azure Cosmos DB 客户端

转载 作者:行者123 更新时间:2023-12-02 05:54:51 24 4
gpt4 key购买 nike

Use a singleton Azure Cosmos DB client for the lifetime of your application

Each DocumentClient instance is thread-safe and performs efficient connection management and address caching when operating in Direct Mode. To allow efficient connection management and better performance by DocumentClient, it is recommended to use a single instance of DocumentClient per AppDomain for the lifetime of the application.

https://learn.microsoft.com/en-us/azure/cosmos-db/performance-tips

services.AddSingleton<IDocumentClient>(x => new DocumentClient(UriEndpoint, MasterKey));

private readonly IDocumentClient _documentClient;
public HomeController(IDocumentClient documentClient){
_documentClient = documentClient;
}

这是否意味着客户端可以用于多个数据库(即任何数据库中的任何容器)?

How do you initialize DocumentDB client as a Singleton in a dotnet core application

最佳答案

正确。数据库和集合是每个文档特定操作的参数,这意味着您可以在多个数据库和集合中完全重用同一客户端。

请记住,这意味着您的数据库或集合之间没有安全隔离。单个主 key 可以访问单个 Azure Cosmos DB 资源中的所有内容。

关于azure - 单例 Azure Cosmos DB 客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56583601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com