Skip to content

Commit

Permalink
Merge pull request #18 from cnblogs/fix-domain-event-dispatch-order
Browse files Browse the repository at this point in the history
fix: domain event dispatch order
  • Loading branch information
ikesnowy authored Feb 9, 2023
2 parents 7e43a23 + a678dbb commit 6a61bae
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public IQueryable<T> GetNoTrackingQueryable<T>()
public async Task<TEntity> AddAsync(TEntity entity)
{
await Context.AddAsync(entity);
await SaveEntitiesInternalAsync(true);
await SaveEntitiesInternalAsync();
return entity;
}

Expand All @@ -61,7 +61,7 @@ public async Task<TEnumerable> AddRangeAsync<TEnumerable>(TEnumerable entities)
where TEnumerable : IEnumerable<TEntity>
{
await Context.AddRangeAsync(entities);
await SaveEntitiesInternalAsync(true);
await SaveEntitiesInternalAsync();
return entities;
}

Expand All @@ -80,22 +80,22 @@ public async Task<TEnumerable> AddRangeAsync<TEnumerable>(TEnumerable entities)
/// <inheritdoc />
public async Task<TEntity> UpdateAsync(TEntity entity)
{
await SaveEntitiesInternalAsync(true);
await SaveEntitiesInternalAsync();
return entity;
}

/// <inheritdoc />
public async Task<IEnumerable<TEntity>> UpdateRangeAsync(IEnumerable<TEntity> entities)
{
await SaveEntitiesInternalAsync(true);
await SaveEntitiesInternalAsync();
return entities;
}

/// <inheritdoc />
public async Task<TEntity> DeleteAsync(TEntity entity)
{
Context.Remove(entity);
await SaveEntitiesInternalAsync(true);
await SaveEntitiesInternalAsync();
return entity;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = de
/// <inheritdoc />
public Task<bool> SaveEntitiesAsync(CancellationToken cancellationToken = default)
{
return SaveEntitiesInternalAsync(false, cancellationToken);
return SaveEntitiesInternalAsync(true, cancellationToken);
}

/// <summary>
Expand All @@ -145,7 +145,7 @@ protected virtual Task BeforeDispatchDomainEventAsync(List<DomainEvent> events,
}

private async Task<bool> SaveEntitiesInternalAsync(
bool dispatchDomainEventFirst,
bool dispatchDomainEventFirst = false,
CancellationToken cancellationToken = default)
{
var entities = Context.ExtractDomainEventSources();
Expand Down

0 comments on commit 6a61bae

Please sign in to comment.