Sl4vP0weR.EventSourcing 1.1.0

This package has a SemVer 2.0.0 package version: 1.1.0+9a4fb173ec940c498636e01ab24ba8c9e6e45789.
dotnet add package Sl4vP0weR.EventSourcing --version 1.1.0                
NuGet\Install-Package Sl4vP0weR.EventSourcing -Version 1.1.0                
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="Sl4vP0weR.EventSourcing" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sl4vP0weR.EventSourcing --version 1.1.0                
#r "nuget: Sl4vP0weR.EventSourcing, 1.1.0"                
#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 Sl4vP0weR.EventSourcing as a Cake Addin
#addin nuget:?package=Sl4vP0weR.EventSourcing&version=1.1.0

// Install Sl4vP0weR.EventSourcing as a Cake Tool
#tool nuget:?package=Sl4vP0weR.EventSourcing&version=1.1.0                

EventSourcing

EventSourcing is a .NET library that implements basis for event sourcing pattern.

Documentation is currently W.I.P.

Installation

Install the package via .NET CLI:

dotnet add package Sl4vP0weR.EventSourcing

Usage

Defining Event Sources

Define type that can be a source for events.

public record User(string Name, string Surname, string PhoneNumber) : IEventSource

Defining Events

Define event representing state changes:

public record UserCreatedEvent(DateTime CreatedAt, User User) : IEvent;

Defining Event Handlers

Define event handler as a type to listen events:

// suitable for any type of event.
public class AuditEventHandler : IEventHandler<IEvent>
{
    public int Order => int.MaxValue; // should run after other handlers
    
    public void Handle(IEvent @event) => PerformAudit(@event);
    
    private void PerformAudit(IEvent @event) 
    {
         // save to the file/database, or send as a message to the message broker/web api, or whatever suits your needs.
        ...
    }
}

Handling events

Create a method event handler instance:

IEventHandler<IEvent> handler = DelegateEventHandler<IEvent>.From(PerformAudit);

or class event handler instance:

IEventHandler<IEvent> handler = new AuditEventHandler();

and listen to the incoming global events:

handler.Listen();

or to the specific source

IEventSource user = new User("Frederic", "Chopin", "123456789");

handler.Listen(user);

Raising events

Create an event:

User user = new User("Frederic", "Chopin", "123456789");

var @event = new UserCreatedEvent(DateTime.UtcNow, user);

Raise event:

@event.Raise();

or with specific sources (still raising global):

@event.Raise(user);

or asynchronous approach:

await @event.RaiseAsync(user);

License

This project is licensed under the MIT License.<br/> See the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible.  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.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen 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
1.1.0 0 1/9/2025