using System.Reflection; using Elsa.EntityFrameworkCore.Modules.Alterations; using Elsa.EntityFrameworkCore.Oracle; using Elsa.Extensions; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Oracle.EntityFrameworkCore.Infrastructure; // ReSharper disable once CheckNamespace namespace Elsa.EntityFrameworkCore.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 { feature.Services.TryAddScopedImplementation(); feature.Services.TryAddScopedImplementation(); feature.Services.TryAddScopedImplementation(); feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaOracle(migrationsAssembly, connectionStringFunc(sp), options, configure: configure); return (TFeature)feature; } }