Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Dzeta.Extensions.CQRS

Utilities for connecting CQRS with EF Core and MediatR.

Features

  • BaseEntity: domain events collection and UpdatedAt maintenance.
  • IDomainEvent: marker interface extending MediatR INotification.
  • IUnitOfWork: abstraction for committing changes (SaveChangesAsync).
  • CqrsDbContext: abstract context that dispatches domain events after persistence, with cycle protection and a virtual MaxEventDispatchIterations.

Install

Add the package from NuGet (after publishing):

dotnet add package Dzeta.Extensions.CQRS

Usage

  1. Inherit your entities from Dzeta.Extensions.CQRS.BaseEntity and raise events:
public sealed class Wallet : BaseEntity
{
    public Guid Id { get; private set; }
    public decimal Balance { get; private set; }

    public void Deposit(decimal amount)
    {
        Balance += amount;
        AddDomainEvent(new DepositHappened(Id, amount));
    }
}
  1. Implement events as IDomainEvent and MediatR handlers in your app layer.

  2. Derive your EF Core context from CqrsDbContext<TContext> and call SaveChangesAsync as usual. Events will be dispatched via IPublisher after each successful save until the queue is empty. Override MaxEventDispatchIterations if needed.

Packaging

This project is configured to generate a NuGet package on build. Run:

dotnet build -c Release

Or to pack explicitly:

dotnet pack -c Release

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages