Skip to content

fix: domain event dispatch order #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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