forked from elsa-workflows/elsa-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ElasticFeatureBase.cs
41 lines (35 loc) · 1.08 KB
/
ElasticFeatureBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Elasticsearch.Net;
using Elsa.Elasticsearch.Extensions;
using Elsa.Elasticsearch.Options;
using Elsa.Elasticsearch.Services;
using Elsa.Features.Abstractions;
using Elsa.Features.Services;
using Microsoft.Extensions.DependencyInjection;
using Nest;
namespace Elsa.Elasticsearch.Common;
public abstract class ElasticFeatureBase : FeatureBase
{
public ElasticFeatureBase(IModule module) : base(module)
{
}
internal ElasticsearchOptions Options { get; set; } = new();
public override void Apply()
{
if (Services.All(x => x.ServiceType != typeof(ElasticClient)))
{
Services.AddSingleton(new ElasticClient(GetSettings()));
}
}
private ConnectionSettings GetSettings()
{
return new ConnectionSettings(new Uri(Options.Endpoint))
.ConfigureAuthentication(Options)
.ConfigureMapping();
}
protected void AddStore<TModel, TStore>() where TModel : class where TStore : class
{
Services
.AddSingleton<ElasticStore<TModel>>()
.AddSingleton<TStore>();
}
}