Class EntityFrameworkDomainEventsPublisher<TDbContext>
- Namespace
- Silverback.Domain
- Assembly
- Silverback.Storage.EntityFramework.dll
Can be used to automatically publish the domain events stored into the domain entities being saved via Entity Framework.
public class EntityFrameworkDomainEventsPublisher<TDbContext> where TDbContext : DbContext
Type Parameters
TDbContextThe type of the DbContext to be managed.
- Inheritance
-
EntityFrameworkDomainEventsPublisher<TDbContext>
- Inherited Members
Constructors
EntityFrameworkDomainEventsPublisher(TDbContext, IPublisher)
Initializes a new instance of the EntityFrameworkDomainEventsPublisher<TDbContext> class.
public EntityFrameworkDomainEventsPublisher(TDbContext dbContext, IPublisher publisher)
Parameters
dbContextTDbContextThe DbContext to be managed.
publisherIPublisherThe IPublisher to be used to publish the events.
EntityFrameworkDomainEventsPublisher(TDbContext, Func<bool, int>, Func<bool, CancellationToken, Task<int>>, IPublisher)
Initializes a new instance of the EntityFrameworkDomainEventsPublisher<TDbContext> class.
public EntityFrameworkDomainEventsPublisher(TDbContext dbContext, Func<bool, int> saveChanges, Func<bool, CancellationToken, Task<int>> saveChangesAsync, IPublisher publisher)
Parameters
dbContextTDbContextThe DbContext to be managed.
saveChangesFunc<bool, int>The method to be used to save the changes.
saveChangesAsyncFunc<bool, CancellationToken, Task<int>>The asynchronous method to be used to save the changes.
publisherIPublisherThe IPublisher to be used to publish the events.
Methods
SaveChangesAndPublishDomainEvents(bool)
Saves all changes made in this context to the database and publishes the domain events stored into the domain entities.
public int SaveChangesAndPublishDomainEvents(bool acceptAllChangesOnSuccess = true)
Parameters
acceptAllChangesOnSuccessboolIndicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.
Returns
- int
The number of state entries written to the database.
SaveChangesAndPublishDomainEventsAsync(bool, CancellationToken)
Saves all changes made in this context to the database and publishes the domain events stored into the domain entities.
public Task<int> SaveChangesAndPublishDomainEventsAsync(bool acceptAllChangesOnSuccess = true, CancellationToken cancellationToken = default)
Parameters
acceptAllChangesOnSuccessboolIndicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.
cancellationTokenCancellationTokenThe token that can be used to request cancellation of the asynchronous operation.