elsa-core/src/modules/Elsa.Persistence.EFCore.SqlServer/SqlServerProvidersExtensions.cs
Sipke Schoorstra ff1f0833ad
Restore EF Core persistence layer (#6931)
* Restore EF Core persistence layer

Originally, we had moved EF Core to the extensions repo, but in practice this turned out to be rather impractical when debugging elsa-core, given that we would lose all of the state (workflow definitions, instances, etc.) across application restarts.

* Integrate PostgreSQL support into EF Core persistence and enhance BlobStorage workflows provider setup.
2025-09-27 20:39:18 +02:00

56 lines
2.5 KiB
C#

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