using System.Reflection; using Elsa.Persistence.EFCore.Modules.Management; using Elsa.Persistence.EFCore.Modules.Runtime; using Elsa.Persistence.EFCore.Oracle.Configurations; using Elsa.Workflows.Management.Entities; using Elsa.Workflows.Runtime.Entities; using JetBrains.Annotations; using Oracle.EntityFrameworkCore.Infrastructure; // ReSharper disable once CheckNamespace namespace Elsa.Persistence.EFCore.Extensions; /// /// Provides extensions to configure EF Core to use Oracle. /// [PublicAPI] public static class OracleProvidersExtensions { private static Assembly Assembly => typeof(OracleProvidersExtensions).Assembly; public static TFeature UseOracle(this PersistenceFeatureBase feature, string connectionString, ElsaDbContextOptions? options = null, Action? configure = null) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseOracle(Assembly, connectionString, options, configure); } public static TFeature UseOracle(this PersistenceFeatureBase feature, Func connectionStringFunc, ElsaDbContextOptions? options = null, Action? configure = null ) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseOracle(Assembly, connectionStringFunc, options, configure); } public static TFeature UseOracle(this PersistenceFeatureBase feature, Assembly migrationsAssembly, string connectionString, ElsaDbContextOptions? options = null, Action? configure = null ) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseOracle(migrationsAssembly, _ => connectionString, options, configure); } public static TFeature UseOracle(this PersistenceFeatureBase feature, Assembly migrationsAssembly, Func connectionStringFunc, ElsaDbContextOptions? options = null, Action? configure = null ) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { options = options.ConfigureOracle(); feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaOracle(migrationsAssembly, connectionStringFunc(sp), options, configure: configure); return (TFeature)feature; } public static ElsaDbContextOptions ConfigureOracle(this ElsaDbContextOptions? options) { options ??= new(); var management = new Management(); var runtime = new Runtime(); options.ConfigureModel(modelBuilder => modelBuilder .ApplyConfiguration(management) .ApplyConfiguration(management)); options.ConfigureModel(modelBuilder => modelBuilder .ApplyConfiguration(runtime) .ApplyConfiguration(runtime) .ApplyConfiguration(runtime) .ApplyConfiguration(runtime) .ApplyConfiguration(runtime)); return options; } public static ElsaDbContextOptions Configure(this ElsaDbContextOptions options) => options.ConfigureOracle(); }