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