Skip to content
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

Introducting synchronous triggers. #161

Merged
merged 4 commits into from
Oct 21, 2022
Merged

Introducting synchronous triggers. #161

merged 4 commits into from
Oct 21, 2022

Conversation

koenbeuk
Copy link
Owner

@koenbeuk koenbeuk commented Oct 21, 2022

This PR adds support for synchronous triggers. As a result, existing triggers types are renamed to properly reflect their async nature. As an example, we now expose:

// Newly added
interface IBeforeSaveTrigger<TEntity> {
  void BeforeSave(ITriggerContext<TEntity> context);
}

// Renamed, used to be IBeforeSaveTrigger<TEntity>
interface IBeforeSaveAsyncTrigger<TEntity> { 
  Task BeforeSaveAsync(<TEntity> context, CancellationToken cancellationToken);
}

This PR will also introduce a proper synchronous path without async-over-sync. Calling dbContext.SaveChanges() will only call synchonous triggers. Both synchronous as well as asynchronous triggers are called when calling dbContext.SaveChangesAsync(). We should consider warning the user when SaveChanges() are being called while asynchronous triggers exists.

As a consequence of this change, the TriggeredDbContext base class has been removed.

This PR will break things!

@koenbeuk koenbeuk merged commit 981c063 into master Oct 21, 2022
@koenbeuk koenbeuk deleted the trigger-refactoring branch October 21, 2022 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant