| | | 1 | | using CShells.Features; |
| | | 2 | | using Elsa.Common.Services; |
| | | 3 | | using Elsa.KeyValues.Contracts; |
| | | 4 | | using Elsa.KeyValues.Entities; |
| | | 5 | | using Elsa.KeyValues.Stores; |
| | | 6 | | using JetBrains.Annotations; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection; |
| | | 8 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 9 | | |
| | | 10 | | namespace Elsa.KeyValues.ShellFeatures; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Installs and configures key-value store features. |
| | | 14 | | /// </summary> |
| | | 15 | | [ShellFeature( |
| | | 16 | | DisplayName = "Key-Value Store", |
| | | 17 | | Description = "Provides key-value storage capabilities for workflows")] |
| | | 18 | | [UsedImplicitly] |
| | | 19 | | public class KeyValueFeature : IShellFeature |
| | | 20 | | { |
| | 0 | 21 | | private static readonly Func<IServiceProvider, IKeyValueStore> DefaultKeyValueStore = sp => ActivatorUtilities.Creat |
| | 0 | 22 | | private Func<IServiceProvider, IKeyValueStore> _keyValueStore = DefaultKeyValueStore; |
| | | 23 | | private bool? _registerMemoryStore; |
| | | 24 | | |
| | | 25 | | /// <summary> |
| | | 26 | | /// A factory that instantiates an <see cref="IKeyValueStore"/>. |
| | | 27 | | /// </summary> |
| | | 28 | | public Func<IServiceProvider, IKeyValueStore> KeyValueStore |
| | | 29 | | { |
| | 0 | 30 | | get => _keyValueStore; |
| | 0 | 31 | | set => _keyValueStore = value; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Whether to register the in-memory backing store used by <see cref="MemoryKeyValueStore"/>. |
| | | 36 | | /// </summary> |
| | | 37 | | public bool RegisterMemoryStore |
| | | 38 | | { |
| | 0 | 39 | | get => _registerMemoryStore ?? ReferenceEquals(KeyValueStore, DefaultKeyValueStore); |
| | 0 | 40 | | set => _registerMemoryStore = value; |
| | | 41 | | } |
| | | 42 | | |
| | | 43 | | public void ConfigureServices(IServiceCollection services) |
| | | 44 | | { |
| | 0 | 45 | | if (RegisterMemoryStore) |
| | 0 | 46 | | services.TryAddSingleton<MemoryStore<SerializedKeyValuePair>>(); |
| | | 47 | | |
| | 0 | 48 | | services.AddScoped<IKeyValueStore>(KeyValueStore); |
| | 0 | 49 | | } |
| | | 50 | | } |