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