| | | 1 | | using JetBrains.Annotations; |
| | | 2 | | using Microsoft.EntityFrameworkCore; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Persistence.EFCore; |
| | | 5 | | |
| | | 6 | | /// <summary> |
| | | 7 | | /// Provides options for configuring Elsa's Entity Framework Core integration. |
| | | 8 | | /// </summary> |
| | | 9 | | [PublicAPI] |
| | | 10 | | public class ElsaDbContextOptions |
| | | 11 | | { |
| | | 12 | | /// <summary> |
| | | 13 | | /// The schema used by Elsa. |
| | | 14 | | /// </summary> |
| | 0 | 15 | | public string? SchemaName { get; set; } |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// The table used to store the migrations history. |
| | | 19 | | /// </summary> |
| | 0 | 20 | | public string? MigrationsHistoryTableName { get; set; } |
| | | 21 | | |
| | | 22 | | /// <summary> |
| | | 23 | | /// The assembly name containing the migrations. |
| | | 24 | | /// </summary> |
| | 0 | 25 | | public string? MigrationsAssemblyName { get; set; } |
| | | 26 | | |
| | 0 | 27 | | public IDictionary<Type, Action<ModelBuilder>> ProviderSpecificConfigurations { get; set; } = new Dictionary<Type, A |
| | | 28 | | |
| | | 29 | | public void ConfigureModel<TDbContext>(Action<ModelBuilder> configure) where TDbContext : DbContext |
| | | 30 | | { |
| | 0 | 31 | | ConfigureModel(typeof(TDbContext), configure); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | public void ConfigureModel(Type dbContextType, Action<ModelBuilder> configure) |
| | | 35 | | { |
| | 0 | 36 | | if (!ProviderSpecificConfigurations.TryGetValue(dbContextType, out var configurations)) |
| | 0 | 37 | | ProviderSpecificConfigurations[dbContextType] = configurations = _ => { }; |
| | | 38 | | |
| | 0 | 39 | | configurations += configure; |
| | 0 | 40 | | ProviderSpecificConfigurations[dbContextType] = configurations; |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | public Action<ModelBuilder> GetModelConfigurations(DbContext dbContext) |
| | | 44 | | { |
| | 0 | 45 | | return GetModelConfigurations(dbContext.GetType()); |
| | | 46 | | } |
| | | 47 | | |
| | | 48 | | public Action<ModelBuilder> GetModelConfigurations(Type dbContextType) |
| | | 49 | | { |
| | 0 | 50 | | return ProviderSpecificConfigurations.TryGetValue(dbContextType, out var providerConfigurations) ? providerConfi |
| | | 51 | | } |
| | | 52 | | } |