Abp模块
abp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

32 lines
881 B

using Microsoft.Extensions.Options;
using Nest;
using System;
using Volo.Abp.DependencyInjection;
namespace Sanhe.Abp.Elasticsearch
{
public class ElasticsearchClientFactory : IElasticsearchClientFactory, ISingletonDependency
{
private readonly AbpElasticsearchOptions _options;
private readonly Lazy<IElasticClient> _lazyClient;
public ElasticsearchClientFactory(
IOptions<AbpElasticsearchOptions> options)
{
_options = options.Value;
_lazyClient = new Lazy<IElasticClient>(CreateClient);
}
public IElasticClient Create() => _lazyClient.Value;
protected virtual IElasticClient CreateClient()
{
var configuration = _options.CreateConfiguration();
var client = new ElasticClient(configuration);
return client;
}
}
}