koenbeuk / EntityFrameworkCore.Triggered

Triggers for EFCore. Respond to changes in your DbContext before and after they are committed to the database.
MIT License
554 stars 29 forks source link

Update readme to reflect synchronous triggers #166

Closed koenbeuk closed 1 year ago

gokhanabatay commented 1 year ago

Why async triggers call both sync and async ones why one interface does not include both sync/async ones just like ef core does.

async -> triggers async method sync -> trigger sync method

public interface IDbContextFactory<[DynamicallyAccessedMembers(DbContext.DynamicallyAccessedMemberTypes)] TContext>
    where TContext : DbContext
{
    /// <summary>
    ///     Creates a new <see cref="DbContext" /> instance.
    /// </summary>
    /// <remarks>
    ///     The caller is responsible for disposing the context; it will not be disposed by any dependency injection container.
    /// </remarks>
    /// <returns>A new context instance.</returns>
    TContext CreateDbContext();

    /// <summary>
    ///     Creates a new <see cref="DbContext" /> instance in an async context.
    /// </summary>
    /// <remarks>
    ///     The caller is responsible for disposing the context; it will not be disposed by any dependency injection container.
    /// </remarks>
    /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
    /// <returns>A task containing the created context that represents the asynchronous operation.</returns>
    /// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception>
    Task<TContext> CreateDbContextAsync(CancellationToken cancellationToken = default)
        => Task.FromResult(CreateDbContext());
}
koenbeuk commented 1 year ago

Why async triggers call both sync and async ones

This is for ergonomics sake. Often you want to have a simple trigger:

class SimpleTrigger : IBeforeSaveTrigger<IEnttiy> { 
    public void BeforeSave(ITriggerContext<IEntity> context) {
      context.ModifiedDate = DateTime.UtcNow;
    }
}

There should be no need to implement an async variant of this trigger

why one interface does not include both sync/async ones just like ef core does.

Again, for ergonomics. In the above example, I'm not interested in anything Async related.

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

koenbeuk commented 1 year ago

This still needs an update