EventSaucing 2.0.3

dotnet add package EventSaucing --version 2.0.3
NuGet\Install-Package EventSaucing -Version 2.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EventSaucing" Version="2.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EventSaucing --version 2.0.3
#r "nuget: EventSaucing, 2.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EventSaucing as a Cake Addin
#addin nuget:?package=EventSaucing&version=2.0.3

// Install EventSaucing as a Cake Tool
#tool nuget:?package=EventSaucing&version=2.0.3

EventSaucing

Add a little EventSauce to your project 😉

This library brings together different stacks to create an Event Sourcing solution.


Reading list before using the project:

Installing

The latest release of EventSaucing is available on NuGet.

Usage

Once referenced in your project you need to configure it in your Startup inside ConfigureServices.

var builder = new ContainerBuilder();

builder.RegisterEventSaucingModules(new EventSaucingConfiguration {
   ConnectionString = // Set your connection string
});

builder.Populate(services); // Populate your services.

var container = builder.Build();

container.StartEventSaucing(); // Start EventSaucing

You can then construct your Aggregates by inheriting from the Aggregate class and including Apply() methods to handle the raised events on the aggregate.

public class FooAggregate : Aggregate {
  public FooAggregate(Guid id) {
    base.Id = id;
  }

  public int Bar { get; set; }

  public void Create(int bar) {
    RaiseEvent(new FooCreated(bar));
  }

  void Apply(FooCreated @event) {			
    Bar = @event.Bar;
  }
}
// A POCO for the event state
public class FooCreated {
  public FooCreated(int bar) {
    Bar = bar;
  }
  public int Bar { get; }
}

You can then create Projectors by inheriting from ProjectorBase and setting up which events to handle. You must also give each projector a unique number. In this example Dapper is used to interact with the persistence store.

[Projector(1)] // The unique projector id.
public class FooProjector: ProjectorBase {
  readonly ConventionBasedCommitProjecter _conventionProjector;

  public FooProjector(IDbService dbService, IPersistStreams persistStreams):base(persistStreams, dbService) {
    var conventionalDispatcher = new ConventionBasedEventDispatcher(c => Checkpoint = c.ToSome())
      .FirstProject<FooCreated>(OnFooCreated)
      .ThenProject<SomeEvent>(OnSomeEventHandler);

    _conventionProjector = new ConventionBasedCommitProjecter(this, dbService, conventionalDispatcher);
  }

  public override void Project(ICommit commit) {
    _conventionProjector.Project(commit);
  }

  private void OnFooCreated(IDbTransaction tx, ICommit commit, FooCreated @event) {
    var sqlParams = new { 
      Id = commit.AggregateId(), 
      Bar = FooCreated.Bar 
    };

    const string sql = @"
      INSERT INTO [dbo].[FooProjector.Foo]
        ([Id]
        ,[Bar])
      SELECT
        @Id
        ,@Bar
      WHERE NOT EXISTS(SELECT * FROM [dbo].[FooProjector.Foo] WHERE Id = @Id);";
    tx.Connection.Execute(sql, (object)sqlParams, tx);
  }

Dependencies

  • Dapper - Used to interact with the sql persistence store.
  • NEventStore - Used for storage of the event stream.
  • Serilog - Used for logging.
  • Akka.NET - Used to deliver deliver events to aggregates & projectors.
  • Autofac - Used for dependency injection.
  • Scalesque - Used to add functional programming in c#.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 184 4/8/2024
2.0.2 162 3/25/2024
2.0.1 205 11/16/2023
2.0.0 83 11/16/2023
1.0.30 86 3/22/2024
1.0.29 410 8/27/2021
1.0.28 330 7/27/2021
1.0.27 393 6/24/2021
1.0.6 676 3/29/2019
1.0.5 755 10/29/2018
1.0.4 997 3/6/2018
1.0.3 944 9/20/2017
1.0.2 954 9/7/2017
1.0.1 1,071 8/1/2017

Bug fix release:

if an exception occurred in a SP, it would restart but stop catching up until user activity occurred, but since in re-hydration there is no user activity until rehydration completes, they just sat there.  SP now catch up on re-start after a crash automatically.

fixed bug where SPs were registered with Akka with random numbers instead of their names which made debugging harder

fixed bug where during catch up, SPs would spam themselves with commit messages that they couldnt project because they were too far ahead of their checkpoint which meant pointless CPU activity and memory leak

fixed bug where if lots of SPs caught up at the same time (eg rehydration) it generated so many Akka messages that dependent SPs effectively came under a denial of service attack! (think 100,000s messages per second)

fixed bug where dependent SPs stopped catching up with proceeding SPs until user acitivity occurred

fixed bug where a lot of Akka dead letter messages were produced on app start up