A collection of domain driven design libraries for .NET designed to lower the barrier to entry for coding domain models
To install dddlib, run the following command in the Package Manager Console:
Install-Package dddlib
Create a domain model, for example:
public class Car : dddlib.AggregateRoot { // used for reconstitution only protected internal Car() { } public Car(string registration) { // business logic goes here... this.Apply( new CarRegistered { Registration = registration }); } [dddlib.NaturalKey] public string Registration { get; private set; } private void Handle(CarRegistered @event) { this.Registration = @event.Registration; } } public class CarRegistered { public string Registration { get; set; } }
To install dddlib.Persistence, run the following command in the Package Manager Console:
Install-Package dddlib.Persistence
Persist the domain model, for example:
// replace with a valid SQL Server connection string var connectionString = @"Server=someServer;Database=someDatabase;"; var repository = new dddlib.Persistence.SqlServer.SqlServerEventStoreRepository( connectionString); var car = new Car("W807ASB"); repository.Save(car); var sameCar = repository.Load<Car>(car.Registration);
To install dddlib.Persistence.EventDispatcher, run the following command in the Package Manager Console:
Install-Package dddlib.Persistence.EventDispatcher
Dispatch the persisted events, for example:
// replace with a valid SQL Server connection string var connectionString = @"Server=someServer;Database=someDatabase;"; using (new dddlib.Persistence.EventDispatcher.SqlServer.SqlServerEventDispatcher( connectionString, (sequenceNumber, @event) => { // action to perform upon dispatch... Console.WriteLine( "{0}: Processed {1}", sequenceNumber, @event.GetType()); })) { // some blocking action Console.ReadLine(); }