作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在.net 核心中构建一个 MVC Web 应用程序,并将使用 CosmosDB 和 DocumentDB API。我一直在阅读,为了表演,你应该
Use a singleton DocumentDB client for the lifetime of your application Note that 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.
services.AddScoped<IDashboard, DashboardService>();
services.AddScoped<IScheduler, SchedulerService>();
services.AddScoped<IMailbox, MailboxService>();
最佳答案
您应该能够使用类似的方法:
services.AddSingleton<IDocumentClient>(x => new DocumentClient(UriEndpoint, MasterKey));
private readonly IDocumentClient _documentClient;
public HomeController(IDocumentClient documentClient){
_documentClient = documentClient;
}
关于.net-core - 如何在 dotnet 核心应用程序中将 DocumentDB 客户端初始化为单例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46160883/
我是一名优秀的程序员,十分优秀!