diff --git a/src/BuildingBlocks/MASA.BuildingBlocks b/src/BuildingBlocks/MASA.BuildingBlocks
index 44285eb4f..c29423b13 160000
--- a/src/BuildingBlocks/MASA.BuildingBlocks
+++ b/src/BuildingBlocks/MASA.BuildingBlocks
@@ -1 +1 @@
-Subproject commit 44285eb4fcb9603c839d1b159824245fd0fbd80b
+Subproject commit c29423b13379a7e69c1d0f31980f03feae3ac4c9
diff --git a/src/Data/Masa.Contrib.Data.EntityFrameworkCore/MasaDbContext.cs b/src/Data/Masa.Contrib.Data.EntityFrameworkCore/MasaDbContext.cs
index 4ec61b4aa..40192da15 100644
--- a/src/Data/Masa.Contrib.Data.EntityFrameworkCore/MasaDbContext.cs
+++ b/src/Data/Masa.Contrib.Data.EntityFrameworkCore/MasaDbContext.cs
@@ -101,18 +101,32 @@ protected virtual void OnBeforeSaveChanges()
{
if (Options != null)
{
- foreach (var filter in Options.SaveChangesFilters)
+ OnBeforeSaveChangesByFilters();
+ DomainEventEnqueueAsync(ChangeTracker).ConfigureAwait(false).GetAwaiter().GetResult();
+ }
+ }
+
+ protected virtual async Task OnBeforeSaveChangesAsync()
+ {
+ if (Options != null)
+ {
+ OnBeforeSaveChangesByFilters();
+ await DomainEventEnqueueAsync(ChangeTracker);
+ }
+ }
+
+ protected virtual void OnBeforeSaveChangesByFilters()
+ {
+ foreach (var filter in Options.SaveChangesFilters)
+ {
+ try
{
- try
- {
- filter.OnExecuting(ChangeTracker);
- }
- catch (Exception ex)
- {
- throw new Exception("An error occured when intercept SaveChanges() or SaveChangesAsync()", ex);
- }
+ filter.OnExecuting(ChangeTracker);
+ }
+ catch (Exception ex)
+ {
+ throw new Exception("An error occured when intercept SaveChanges() or SaveChangesAsync()", ex);
}
- DomainEventEnqueueAsync(ChangeTracker).ConfigureAwait(false).GetAwaiter().GetResult();
}
}
@@ -151,10 +165,10 @@ protected virtual async Task DomainEventEnqueueAsync(ChangeTracker changeTracker
///
///
///
- public sealed override Task SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
+ public sealed override async Task SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default)
{
- OnBeforeSaveChanges();
- return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
+ await OnBeforeSaveChangesAsync();
+ return await base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken);
}
}