Class DbContextEventsPublisher
Exposes some methods to handle domain events as part of the SaveChanges transaction.
Inherited Members
Namespace: Silverback.EntityFrameworkCore
Assembly: Silverback.Core.EFCore30.dll
Syntax
public class DbContextEventsPublisher
Constructors
| Improve this doc View sourceDbContextEventsPublisher(IPublisher, DbContext)
Initializes a new instance of the DbContextEventsPublisher class.
Declaration
public DbContextEventsPublisher(IPublisher publisher, DbContext dbContext)
Parameters
Type | Name | Description |
---|---|---|
IPublisher | publisher | The IPublisher to be used to publish the events to the internal bus. |
DbContext | dbContext | The DbContext to be scanned for domain events. |
DbContextEventsPublisher(Func<object, IEnumerable<object>?>, Action<object>, IPublisher, DbContext)
Initializes a new instance of the DbContextEventsPublisher class.
Declaration
public DbContextEventsPublisher(Func<object, IEnumerable<object>?> eventsSelector, Action<object> clearEventsAction, IPublisher publisher, DbContext dbContext)
Parameters
Type | Name | Description |
---|---|---|
Func<object, IEnumerable<object>> | eventsSelector | The custom delegate to be used to get the events out of the entities being saved. |
Action<object> | clearEventsAction | The custom delegate to be used to clear the events from the entities after they have been published. |
IPublisher | publisher | The IPublisher to be used to publish the events to the internal bus. |
DbContext | dbContext | The DbContext to be scanned for domain events. |
Methods
| Improve this doc View sourceExecuteSaveTransaction(Func<int>)
Publishes the domain events generated by the tracked entities and then executes the provided save changes procedure.
Declaration
public int ExecuteSaveTransaction(Func<int> saveChanges)
Parameters
Type | Name | Description |
---|---|---|
Func<int> | saveChanges | The delegate to the original |
Returns
Type | Description |
---|---|
int | The number of entities saved to the database. |
ExecuteSaveTransactionAsync(Func<Task<int>>)
Publishes the domain events generated by the tracked entities and then executes the provided save changes procedure.
Declaration
public Task<int> ExecuteSaveTransactionAsync(Func<Task<int>> saveChangesAsync)
Parameters
Type | Name | Description |
---|---|---|
Func<Task<int>> | saveChangesAsync | The delegate to the original |
Returns
Type | Description |
---|---|
Task<int> | A Task<TResult> representing the asynchronous operation. The task result contains the number of entities saved to the database. |