Base libraries to start with CQRS and Event Sourcing
The solution consists of a number of projects, each published as a NuGet package on myget (https://www.myget.org/F/pgs-ddd/api/v2).
It should be ready to build out-of-the box. To work with the dependencies Paket is used. It is best handled from the command line. There is a handy VS plugin too.
This library should be referenced by the business domain. This is there Aggregate Roots, Entities and Domain Events live.
To create an event-sourced AR, just inherit the AggregateRoot<TId>
class.
public class BusinessPerson : AggregateRoot<PersonId>
{
private CompanyId _employer;
public BusinessPerson(PersonId id) : base(id) { }
public void StartWorkAt(CompanyId company)
{
// maybe some buisiness checks here to ensure consistent state?
// push event
Handle(StartedWorkingAt(company));
}
// each event is handled in a OnX method
// it should be private or protected
private void OnStartedWorkingAt(StartedWorkingAt ev)
{
_employer = ev.CompanyId;
}
// keeping event classes nested in their respective Aggregate Root
// helps prevent name clashes
public class StartedWorkingAt : DomainEvent
{
public StartedWorkingAt(CompanyId company)
{
}
}
}
This one should be referenced by Application services layer and contains base interfaces for their implementation:
IEventPublisher
,IEventHandler
- for working with domain eventsIServiceBus
- combines both aboveIIdConverter<TId>
- to convert domain ids into event stream identifiers
Implementation of an in-memory event store and a repository backed by events persisted to hard storage
An implementation of event store using NEventStore.
Basic, in-memory implementation of IServiceBus
.