| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Persistence.EFCore.EntityHandlers; |
| | | 3 | | using Elsa.Persistence.EFCore.Sqlite; |
| | | 4 | | using Elsa.Extensions; |
| | | 5 | | using Microsoft.EntityFrameworkCore.Infrastructure; |
| | | 6 | | using Microsoft.Extensions.DependencyInjection; |
| | | 7 | | using Microsoft.Extensions.DependencyInjection.Extensions; |
| | | 8 | | |
| | | 9 | | // ReSharper disable once CheckNamespace |
| | | 10 | | namespace Elsa.Persistence.EFCore.Extensions; |
| | | 11 | | |
| | | 12 | | /// <summary> |
| | | 13 | | /// Provides extensions to configure EF Core to use Sqlite. |
| | | 14 | | /// </summary> |
| | | 15 | | public static class SqliteProvidersExtensions |
| | | 16 | | { |
| | 2 | 17 | | private static Assembly Assembly => typeof(SqliteProvidersExtensions).Assembly; |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Configures the feature to use Sqlite. |
| | | 21 | | /// </summary> |
| | | 22 | | public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 23 | | string? connectionString = null, |
| | | 24 | | ElsaDbContextOptions? options = null, |
| | | 25 | | Action<SqliteDbContextOptionsBuilder>? configure = null) |
| | | 26 | | where TDbContext : ElsaDbContextBase |
| | | 27 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 28 | | { |
| | 2 | 29 | | return feature.UseSqlite(Assembly, connectionString, options, configure); |
| | | 30 | | } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// Configures the feature to use Sqlite. |
| | | 34 | | /// </summary> |
| | | 35 | | public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 36 | | Func<IServiceProvider, string> connectionStringFunc, |
| | | 37 | | ElsaDbContextOptions? options = null, |
| | | 38 | | Action<SqliteDbContextOptionsBuilder>? configure = null) |
| | | 39 | | where TDbContext : ElsaDbContextBase |
| | | 40 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 41 | | { |
| | 0 | 42 | | return feature.UseSqlite(Assembly, connectionStringFunc, options, configure); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Configures the feature to use Sqlite. |
| | | 47 | | /// </summary> |
| | | 48 | | public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 49 | | Assembly migrationsAssembly, |
| | | 50 | | string? connectionString = null, |
| | | 51 | | ElsaDbContextOptions? options = null, |
| | | 52 | | Action<SqliteDbContextOptionsBuilder>? configure = null) |
| | | 53 | | where TDbContext : ElsaDbContextBase |
| | | 54 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 55 | | { |
| | 2 | 56 | | connectionString ??= "Data Source=elsa.sqlite.db;Cache=Shared;"; |
| | 2 | 57 | | return feature.UseSqlite(migrationsAssembly, _ => connectionString, options, configure); |
| | | 58 | | } |
| | | 59 | | |
| | | 60 | | /// <summary> |
| | | 61 | | /// Configures the feature to use Sqlite. |
| | | 62 | | /// </summary> |
| | | 63 | | public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 64 | | Assembly migrationsAssembly, |
| | | 65 | | Func<IServiceProvider, string> connectionStringFunc, |
| | | 66 | | ElsaDbContextOptions? options = null, |
| | | 67 | | Action<SqliteDbContextOptionsBuilder>? configure = null) |
| | | 68 | | where TDbContext : ElsaDbContextBase |
| | | 69 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 70 | | { |
| | 2 | 71 | | feature.Module.Services.TryAddScopedImplementation<IEntityModelCreatingHandler, SetupForSqlite>(); |
| | 2 | 72 | | feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlite(migrationsAssembly, connectionStringFunc(sp), opt |
| | 2 | 73 | | return (TFeature)feature; |
| | | 74 | | } |
| | | 75 | | } |