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