< Summary

Information
Class: Elsa.Persistence.EFCore.CombinedPersistenceShellFeatureBase
Assembly: Elsa.Persistence.EFCore.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/CombinedPersistenceShellFeatureBase.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 26
Coverable lines: 26
Total lines: 106
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_ConnectionString()100%210%
get_DbContextOptions()100%210%
get_UseContextPooling()100%210%
get_RunMigrations()100%210%
get_DbContextFactoryLifetime()100%210%
ConfigureServices(...)100%210%
OnConfiguring(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Common/CombinedPersistenceShellFeatureBase.cs

#LineLine coverage
 1using CShells.Features;
 2using Microsoft.Extensions.DependencyInjection;
 3
 4// ReSharper disable once CheckNamespace
 5namespace Elsa.Persistence.EFCore;
 6
 7/// <summary>
 8/// Base class for combined persistence shell features that provide unified configuration
 9/// for multiple persistence components (definitions, instances, runtime, etc.).
 10///
 11/// This base class handles registering <see cref="SharedPersistenceSettings"/> so that
 12/// dependent persistence features can use the shared settings as a fallback when
 13/// feature-specific settings are not provided.
 14/// </summary>
 15/// <remarks>
 16/// <para>
 17/// By using this base class, users can configure persistence settings once at the
 18/// combined feature level instead of repeating configuration for each dependent feature.
 19/// </para>
 20/// <example>
 21/// Example appsettings.json with unified configuration:
 22/// <code>
 23/// {
 24///   "CShells": {
 25///     "Shells": [{
 26///       "Settings": {
 27///         "SqliteWorkflowPersistence": {
 28///           "ConnectionString": "Data Source=elsa.db;Cache=Shared",
 29///           "DbContextOptions": {
 30///             "EnableSensitiveDataLogging": false
 31///           }
 32///         }
 33///       },
 34///       "Features": ["SqliteWorkflowPersistence"]
 35///     }]
 36///   }
 37/// }
 38/// </code>
 39/// </example>
 40/// </remarks>
 41public abstract class CombinedPersistenceShellFeatureBase : IShellFeature
 42{
 43    /// <summary>
 44    /// Gets or sets the connection string to use for the database.
 45    /// This setting is shared with all dependent persistence features.
 46    /// </summary>
 047    public string? ConnectionString { get; set; }
 48
 49    /// <summary>
 50    /// Gets or sets additional options to configure the database context.
 51    /// This setting is shared with all dependent persistence features.
 52    /// </summary>
 053    public ElsaDbContextOptions? DbContextOptions { get; set; }
 54
 55    /// <summary>
 56    /// Gets or sets a value indicating whether to use context pooling.
 57    /// This setting is shared with all dependent persistence features.
 58    /// </summary>
 059    public bool? UseContextPooling { get; set; }
 60
 61    /// <summary>
 62    /// Gets or sets a value indicating whether to run migrations.
 63    /// This setting is shared with all dependent persistence features.
 64    /// </summary>
 065    public bool? RunMigrations { get; set; }
 66
 67    /// <summary>
 68    /// Gets or sets the lifetime of the DbContextFactory.
 69    /// This setting is shared with all dependent persistence features.
 70    /// </summary>
 071    public ServiceLifetime? DbContextFactoryLifetime { get; set; }
 72
 73    /// <inheritdoc />
 74    public void ConfigureServices(IServiceCollection services)
 75    {
 76        // Register shared settings that dependent features will use as fallback
 077        services.Configure<SharedPersistenceSettings>(options =>
 078        {
 079            // Only set values that were explicitly configured
 080            if (ConnectionString != null)
 081                options.ConnectionString = ConnectionString;
 082
 083            if (DbContextOptions != null)
 084                options.DbContextOptions = DbContextOptions;
 085
 086            if (UseContextPooling.HasValue)
 087                options.UseContextPooling = UseContextPooling;
 088
 089            if (RunMigrations.HasValue)
 090                options.RunMigrations = RunMigrations;
 091
 092            if (DbContextFactoryLifetime.HasValue)
 093                options.DbContextFactoryLifetime = DbContextFactoryLifetime;
 094        });
 95
 096        OnConfiguring(services);
 097    }
 98
 99    /// <summary>
 100    /// Override this method to add additional service registrations.
 101    /// </summary>
 102    protected virtual void OnConfiguring(IServiceCollection services)
 103    {
 0104    }
 105}
 106