Show / Hide Table of Contents

    Class EntityFrameworkDomainEventsPublisher<TDbContext>

    Can be used to automatically publish the domain events stored into the domain entities being saved via Entity Framework.

    Inheritance
    object
    EntityFrameworkDomainEventsPublisher<TDbContext>
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: Silverback.Domain
    Assembly: Silverback.Storage.EntityFramework.dll
    Syntax
    public class EntityFrameworkDomainEventsPublisher<TDbContext> where TDbContext : DbContext
    Type Parameters
    Name Description
    TDbContext

    The type of the DbContext to be managed.

    Constructors

    EntityFrameworkDomainEventsPublisher(TDbContext, IPublisher)

    Initializes a new instance of the EntityFrameworkDomainEventsPublisher<TDbContext> class.

    Declaration
    public EntityFrameworkDomainEventsPublisher(TDbContext dbContext, IPublisher publisher)
    Parameters
    Type Name Description
    TDbContext dbContext

    The DbContext to be managed.

    IPublisher publisher

    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.

    Declaration
    public EntityFrameworkDomainEventsPublisher(TDbContext dbContext, Func<bool, int> saveChanges, Func<bool, CancellationToken, Task<int>> saveChangesAsync, IPublisher publisher)
    Parameters
    Type Name Description
    TDbContext dbContext

    The DbContext to be managed.

    Func<bool, int> saveChanges

    The method to be used to save the changes.

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

    The asynchronous method to be used to save the changes.

    IPublisher publisher

    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.

    Declaration
    public int SaveChangesAndPublishDomainEvents(bool acceptAllChangesOnSuccess = true)
    Parameters
    Type Name Description
    bool acceptAllChangesOnSuccess

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

    Returns
    Type Description
    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.

    Declaration
    public Task<int> SaveChangesAndPublishDomainEventsAsync(bool acceptAllChangesOnSuccess = true, CancellationToken cancellationToken = default)
    Parameters
    Type Name Description
    bool acceptAllChangesOnSuccess

    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
    Type Description
    Task<int>

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

    GitHub E-Mail
    ↑ Back to top © 2026 Sergio Aquilini