rename DbExceptionHandlers to better reflect their intent.

This commit is contained in:
Raymond den Haan 2024-08-13 14:29:25 +02:00
parent c8669d1bc1
commit aa28329e47
10 changed files with 20 additions and 22 deletions

View file

@ -23,7 +23,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreIdentityPersistenceFeature UsePostgreSql(this EFCoreIdentityPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -33,7 +33,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreAlterationsPersistenceFeature UsePostgreSql(this EFCoreAlterationsPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -43,7 +43,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreLabelPersistenceFeature UsePostgreSql(this EFCoreLabelPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -53,7 +53,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreWorkflowDefinitionPersistenceFeature UsePostgreSql(this EFCoreWorkflowDefinitionPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -63,7 +63,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreWorkflowInstancePersistenceFeature UsePostgreSql(this EFCoreWorkflowInstancePersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -73,7 +73,7 @@ public static class PostgreSqlProvidersExtensions
public static WorkflowManagementPersistenceFeature UsePostgreSql(this WorkflowManagementPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
@ -83,7 +83,7 @@ public static class PostgreSqlProvidersExtensions
public static EFCoreWorkflowRuntimePersistenceFeature UsePostgreSql(this EFCoreWorkflowRuntimePersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = default)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
feature.DbExceptionHandler = _ => new DbExceptionHandler();
feature.DbExceptionHandler = _ => new DbExceptionTransformer();
return feature;
}
}

View file

@ -10,16 +10,14 @@ using Npgsql;
namespace Elsa.EntityFrameworkCore.PostgreSql.Handlers;
/// <summary>
/// Handles database exceptions encountered when using a postgreSQL database.
/// </summary>
public class DbExceptionHandler : IDbExceptionHandler<AlterationsElsaDbContext>,
/// Transforms database exceptions encountered when using a postgreSQL database into more generic exceptions.
public class DbExceptionTransformer : IDbExceptionHandler<AlterationsElsaDbContext>,
IDbExceptionHandler<IdentityElsaDbContext>,
IDbExceptionHandler<LabelsElsaDbContext>,
IDbExceptionHandler<ManagementElsaDbContext>,
IDbExceptionHandler<RuntimeElsaDbContext>
{
/// Handles database exceptions encountered when using a postgreSQL database.
/// Transforms database exceptions encountered when using a postgreSQL database into more generic exceptions.
public void Handle(DbUpdateException exception)
{
var ex = exception.InnerException as PostgresException;

View file

@ -8,14 +8,14 @@ using Microsoft.EntityFrameworkCore;
namespace Elsa.EntityFrameworkCore.Handlers;
/// A No-Op database exception handler.
public class NoopDbExceptionHandler : IDbExceptionHandler<AlterationsElsaDbContext>,
/// A database exception handler that rethrows the original exception.
public class RethrowDbExceptionHandler : IDbExceptionHandler<AlterationsElsaDbContext>,
IDbExceptionHandler<IdentityElsaDbContext>,
IDbExceptionHandler<LabelsElsaDbContext>,
IDbExceptionHandler<ManagementElsaDbContext>,
IDbExceptionHandler<RuntimeElsaDbContext>
{
/// Handles the given exception that occurs during database operations.
/// rethrows the given exception that occurs during database operations.
public void Handle(DbUpdateException exception)
{
throw exception;

View file

@ -16,7 +16,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Alterations;
public class EFCoreAlterationsPersistenceFeature(IModule module) : PersistenceFeatureBase<AlterationsElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<AlterationsElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<AlterationsElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()

View file

@ -18,7 +18,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Identity;
public class EFCoreIdentityPersistenceFeature(IModule module) : PersistenceFeatureBase<IdentityElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<IdentityElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<IdentityElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()

View file

@ -14,7 +14,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Labels;
public class EFCoreLabelPersistenceFeature(IModule module) : PersistenceFeatureBase<LabelsElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<LabelsElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<LabelsElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
public override void Configure()
{

View file

@ -16,7 +16,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Management;
public class EFCoreWorkflowDefinitionPersistenceFeature(IModule module) : PersistenceFeatureBase<ManagementElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()

View file

@ -16,7 +16,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Management;
public class EFCoreWorkflowInstancePersistenceFeature(IModule module) : PersistenceFeatureBase<ManagementElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()

View file

@ -20,7 +20,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Management;
public class WorkflowManagementPersistenceFeature(IModule module) : PersistenceFeatureBase<ManagementElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<ManagementElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()

View file

@ -18,7 +18,7 @@ namespace Elsa.EntityFrameworkCore.Modules.Runtime;
public class EFCoreWorkflowRuntimePersistenceFeature(IModule module) : PersistenceFeatureBase<RuntimeElsaDbContext>(module)
{
/// Delegate for determining the exception handler.
public Func<IServiceProvider, IDbExceptionHandler<RuntimeElsaDbContext>> DbExceptionHandler { get; set; } = _ => new NoopDbExceptionHandler();
public Func<IServiceProvider, IDbExceptionHandler<RuntimeElsaDbContext>> DbExceptionHandler { get; set; } = _ => new RethrowDbExceptionHandler();
/// <inheritdoc />
public override void Configure()