| | | 1 | | using System.Reflection; |
| | | 2 | | using Elsa.Persistence.EFCore.Modules.Runtime; |
| | | 3 | | using Microsoft.EntityFrameworkCore.Infrastructure; |
| | | 4 | | |
| | | 5 | | // ReSharper disable once CheckNamespace |
| | | 6 | | namespace Elsa.Persistence.EFCore.Extensions; |
| | | 7 | | |
| | | 8 | | /// <summary> |
| | | 9 | | /// Provides extensions to configure EF Core to use SQL Server. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class SqlServerProvidersExtensions |
| | | 12 | | { |
| | 12 | 13 | | private static Assembly Assembly => typeof(SqlServerProvidersExtensions).Assembly; |
| | | 14 | | |
| | | 15 | | public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 16 | | string connectionString, |
| | | 17 | | ElsaDbContextOptions? options = null, |
| | | 18 | | Action<SqlServerDbContextOptionsBuilder>? configure = null) |
| | | 19 | | where TDbContext : ElsaDbContextBase |
| | | 20 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 21 | | { |
| | 12 | 22 | | return feature.UseSqlServer(Assembly, connectionString, options, configure); |
| | | 23 | | } |
| | | 24 | | |
| | | 25 | | public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 26 | | Func<IServiceProvider, string> connectionStringFunc, |
| | | 27 | | ElsaDbContextOptions? options = null, |
| | | 28 | | Action<SqlServerDbContextOptionsBuilder>? configure = null) |
| | | 29 | | where TDbContext : ElsaDbContextBase |
| | | 30 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 31 | | { |
| | 0 | 32 | | return feature.UseSqlServer(Assembly, connectionStringFunc, options, configure); |
| | | 33 | | } |
| | | 34 | | |
| | | 35 | | public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 36 | | Assembly migrationsAssembly, |
| | | 37 | | string connectionString, |
| | | 38 | | ElsaDbContextOptions? options = null, |
| | | 39 | | Action<SqlServerDbContextOptionsBuilder>? configure = null) |
| | | 40 | | where TDbContext : ElsaDbContextBase |
| | | 41 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 42 | | { |
| | 2364 | 43 | | return feature.UseSqlServer(migrationsAssembly, _ => connectionString, options, configure); |
| | | 44 | | } |
| | | 45 | | |
| | | 46 | | public static TFeature UseSqlServer<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature, |
| | | 47 | | Assembly migrationsAssembly, |
| | | 48 | | Func<IServiceProvider, string> connectionStringFunc, |
| | | 49 | | ElsaDbContextOptions? options = null, |
| | | 50 | | Action<SqlServerDbContextOptionsBuilder>? configure = null) |
| | | 51 | | where TDbContext : ElsaDbContextBase |
| | | 52 | | where TFeature : PersistenceFeatureBase<TFeature, TDbContext> |
| | | 53 | | { |
| | 2364 | 54 | | feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlServer(migrationsAssembly, connectionStringFunc(sp), |
| | 12 | 55 | | if (feature is EFCoreWorkflowRuntimePersistenceFeature runtimePersistenceFeature) |
| | 3 | 56 | | runtimePersistenceFeature.UseWorkflowCommitTransaction = true; |
| | 12 | 57 | | return (TFeature)feature; |
| | | 58 | | } |
| | | 59 | | } |