using System.Reflection; using Microsoft.EntityFrameworkCore.Infrastructure; // ReSharper disable once CheckNamespace namespace Elsa.Persistence.EFCore.Extensions; /// /// Provides extensions to configure EF Core to use SQL Server. /// public static class SqlServerProvidersExtensions { private static Assembly Assembly => typeof(SqlServerProvidersExtensions).Assembly; public static TFeature UseSqlServer(this PersistenceFeatureBase feature, string connectionString, ElsaDbContextOptions? options = null, Action? configure = null) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseSqlServer(Assembly, connectionString, options, configure); } public static TFeature UseSqlServer(this PersistenceFeatureBase feature, Func connectionStringFunc, ElsaDbContextOptions? options = null, Action? configure = null) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseSqlServer(Assembly, connectionStringFunc, options, configure); } public static TFeature UseSqlServer(this PersistenceFeatureBase feature, Assembly migrationsAssembly, string connectionString, ElsaDbContextOptions? options = null, Action? configure = null) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { return feature.UseSqlServer(migrationsAssembly, _ => connectionString, options, configure); } public static TFeature UseSqlServer(this PersistenceFeatureBase feature, Assembly migrationsAssembly, Func connectionStringFunc, ElsaDbContextOptions? options = null, Action? configure = null) where TDbContext : ElsaDbContextBase where TFeature : PersistenceFeatureBase { feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlServer(migrationsAssembly, connectionStringFunc(sp), options, configure); return (TFeature)feature; } }