用于 Elasticsearch 的 .NET NEST 客户端

.NET NEST client for Elasticsearch

新建客户端实例时,有以下区别吗:

services.AddSingleton<IElasticClient>(new ElasticClient(settings)

var client = new ElasticClient(settings)

变量 settingsvar settings = new ConnectionSettings(node) 其中节点是 var node = new Uri("http://localhost:9200")

在第一个代码中,您将弹性客户端作为单例实例添加到 .net 中的 DI 框架,而在第二个代码中,您将实例化弹性客户端的新实例。 如果您将 ElasticClient 注册为单例服务,您可以随时进行构造函数注入以使用它,并且您的应用程序中将有一个实例,而第二种方法每次都会创建新对象。 可以看看.net官方的Dependecy Injection frameworkhere.

.