2023-10-07 10:47:36 +00:00
|
|
|
using System.Reflection;
|
2023-05-28 09:56:49 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
2023-11-19 09:22:13 +00:00
|
|
|
using Microsoft.EntityFrameworkCore.Migrations;
|
|
|
|
|
|
2023-05-28 09:56:49 +00:00
|
|
|
namespace Elsa.EntityFrameworkCore.Common;
|
|
|
|
|
|
2023-05-28 14:40:10 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Provides options for configuring Elsa's Entity Framework Core integration.
|
|
|
|
|
/// </summary>
|
2023-05-28 09:56:49 +00:00
|
|
|
public static class ElsaDbContextOptionsExtensions
|
|
|
|
|
{
|
2023-05-28 14:40:10 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// Installs a custom extension for Elsa's Entity Framework Core integration.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="optionsBuilder">The options builder to install the extension on.</param>
|
|
|
|
|
/// <param name="options">The options to install.</param>
|
|
|
|
|
public static DbContextOptionsBuilder UseElsaDbContextOptions(this DbContextOptionsBuilder optionsBuilder, ElsaDbContextOptions? options)
|
2023-05-28 09:56:49 +00:00
|
|
|
{
|
2023-05-28 14:40:10 +00:00
|
|
|
((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(new ElsaDbContextOptionsExtension(options));
|
2023-11-19 09:22:13 +00:00
|
|
|
optionsBuilder.ReplaceService<IMigrationsAssembly, DbSchemaAwareMigrationAssembly>();
|
2023-05-28 09:56:49 +00:00
|
|
|
return optionsBuilder;
|
|
|
|
|
}
|
2023-10-07 10:47:36 +00:00
|
|
|
|
|
|
|
|
public static string GetMigrationsAssemblyName(this ElsaDbContextOptions? options, Assembly migrationsAssembly) => options?.MigrationsAssemblyName ?? migrationsAssembly.GetName().Name!;
|
|
|
|
|
public static string GetMigrationsHistoryTableName(this ElsaDbContextOptions? options) => options?.MigrationsHistoryTableName ?? ElsaDbContextBase.MigrationsHistoryTable;
|
|
|
|
|
public static string GetSchemaName(this ElsaDbContextOptions? options) => options?.SchemaName ?? ElsaDbContextBase.ElsaSchema;
|
2023-05-28 09:56:49 +00:00
|
|
|
}
|