Table of Contents

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

TDbContext

The 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

dbContext TDbContext

The DbContext to be managed.

publisher IPublisher

The 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

dbContext TDbContext

The DbContext to be managed.

saveChanges Func<bool, int>

The method to be used to save the changes.

saveChangesAsync Func<bool, CancellationToken, Task<int>>

The asynchronous method to be used to save the changes.

publisher IPublisher

The 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

acceptAllChangesOnSuccess bool

Indicates 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

acceptAllChangesOnSuccess bool

Indicates whether AcceptAllChanges() is called after the changes have been sent successfully to the database.

cancellationToken CancellationToken

The token that can be used to request cancellation of the asynchronous operation.

Returns

Task<int>

A Task representing the asynchronous operation. The task result contains the number of state entries written to the database.