Sharpino 1.4.7

There is a newer version of this package available.
See the version list below for details.
dotnet add package Sharpino --version 1.4.7
NuGet\Install-Package Sharpino -Version 1.4.7
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="Sharpino" Version="1.4.7" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Sharpino --version 1.4.7
#r "nuget: Sharpino, 1.4.7"
#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 Sharpino as a Cake Addin
#addin nuget:?package=Sharpino&version=1.4.7

// Install Sharpino as a Cake Tool
#tool nuget:?package=Sharpino&version=1.4.7

Sharpino

<img src="ico/sharpino.png" alt="drawing" width="50"/>

A little F# event-sourcing library

NuGet version (Sharpino) License: MIT

What is it?

Support for Event-sourcing in F#. No sensible data (GDPR) support.

Features

  • Support in memory and Postgres storage. Support Eventstoredb (only for the LightCommandHandler).
  • Support publishing events to Kafka.
  • Example application with tests including Kafka subscriber.
  • Contexts represent sets of collections of entities (e.g. a collection of todos, a collection of tags, a collection of categories, etc.) associated with events
  • A specific practice to refactor context and test context refactoring
  • Send events to Apache Kafka

Projects

Sharpino.Lib:

  • Core.fs: Abstract definition of Events, Commands and Undoer (the reverse of a command to be used if storage lacks transaction between streams). Definition of EvolveUnForgivingErrors and "normal" Evolve. The former raises an error if there are some events that cannot be applied to the current state of the context. The latter just skip those events.

  • CommandHandler.fs: gets and stores snapshots, execute commands, and produces and store events using the storage.

  • LightCommandHandler.fs: gets and stores snapshots, execute commands, produces and store events using a storage that supports pub/sub model (only Eventstoredb at the moment).

  • DbStorage.fs and MemoryStorage.fs: Manages persistency in Postgres or in-memory.

  • Cache.fs. Cache current state.

Sharpino.Sample You need a user called 'safe' with password 'safe' in your Postgres (if you want to use Postgres as Eventstore).

It is an example of a library for managing todos with tags and categories. There are two versions in the sense of two different configurations concerning the distribution of the models (collection of entities) between the contexts. There is a strategy to test the migration between versions (contexts refactoring) that is described in the code (See: AppVersions.fs and MultiVersionsTests.fs .

  • contexts (e.g. TodosContext) own a partition of the models and provide members to handle them.

  • contexts members have corresponding events (e.g. TagsEvents) that are Discriminated Unions cases. Event types implement the Process interface.

  • contexts are related to Commands (e.g. TagCommand) that are Discriminated Unions cases that can return lists of events by implementing the Executable interface.

Commands defines also undoers are functions that can undo the commands to reverse action in a multiple-stream operation for storage that doesn't support multiple-stream transactions (see LightCommandHandler).

  • A Storage stores and retrieves events and snapshots.
  • The api layer functions provide business logic involving one or more clusters by accessing their state, and by building one or more commands and sending them to the CommandHandler.
  • An example of how to handle multiple versions of the application to help refactoring and migration between different versions: application versions.

Sharpino.Sample.tests

  • tests for the sample application

Sharpino.Sample.Kafka

  • scripts to setup a Kafka topics corresponding to the contexts of the sample application

How to use it

  • You can run the sample application as a rest service by running the following command from Sharpino.Sample folder:
dotnet run
  • You can run the client Fable/Elmish sample application by running the following command from the Sharpino.Sample.Client folder:
npm install
npm start
  • Just use ordinary dotnet command line tools for building the solution. Particularly you can run tests of the sample application by using the following command:
dotnet test 

You can also run the tests by the following command from Sharpino.Sample.Tests folder:

dotnet run

In the latter case, you get the output from Expecto test runner (in this case the console shows eventual standard output/printf).

By default, the tests run only the in-memory implementation of the storage. You can set up the Postgres tables and db by using dbmate. In the Sharpino.Sample folder you can run the following command to set up the Postgres database:

dbmate -e up

(see the .env to set up the DATABASE_URL environment variable to connect to the Postgres database with a connection string). If you have Eventstore the standard configuration should work. (I have tested it with Eventstore 20.10.2-alpha on M2 Apple Silicon chip under Docker).

Tests on eventstoredb

If eventstore is running on docker you may want to run tests on it as follows: by making the eventstore tests not pending (search for "eventstore tests" and change ptestList to ftestList) or by uncommenting the following line on the file MultiversionsTests.fs:

        // (AppVersions.evSApp,                    AppVersions.evSApp,                 fun () -> () |> Result.Ok)

Faq:

  • Why "Sharpino"?
    • It's a mix of Sharp and fino (Italian for "thin"). "sciarpino" (same pronunciation) in Italian means also "little scarf".
  • Why another event-sourcing library?
    • I wanted to study the subject and it ended up in a tiny little framework.
  • Why F#?
    • Any functional language from the ML family language in my opinion is a good fit for the following reasons:
      • Events are immutable, building the state of the context is a function of those events.
      • Discriminated Unions are suitable to represent events and commands.
      • The use of the lambda expression is a nice trick for the undoers (the under is returned as a lambda that retrieves the context for applying the undo and returns another lambda that actually can "undo" the command).
      • It is a .net language, so you can use everything in the .net ecosystem (including C# libraries).
  • How to use it
    • add the nuget package Sharpino to your project (current version 1.0.1)
    • note: on my side, when I added Sharpino as a library into a web app, then I had to add the following line to the web app project file to avoid a false error (the error was "A function labeled with the 'EntryPointAttribute' attribute must be the last declaration")
    <GenerateProgramFile>false</GenerateProgramFile>
    

News:

  • Version 1.4.0: runCommand instead of Result<unit, string> returns, under result, info about event-store created IDs (Postgres based) of new events and eventually Kafka Delivery result (if Kafka is configured).

  • Version 1.3.9: Repository interface changed (using Result type when it is needed). Note: the new Repository interface (and implementation) is not compatible with the one introduced in Version 1.3.8!

  • Version 1.3.8: can use a new Repository type instead of lists (even though they are still implemented as plain lists at the moment) to handle collections of entities.

  • Version 1.3.5: the library is split into two nuget packages: Sharpino.Core and Sharpino.Lib. the Sharpino.Core can be included in a Shared project in the Fable Remoting style. The collections of the entities used in the Sharpino.Sample are not lists anymore but use Repository data type (which at the moment uses plain lists anyway).

  • Version 1.3.4 there is the possibility to choose a pessimistic lock (or not) in command processing. Needed a configuration file named appSettings.json in the root of the project with the following content:


    "SharpinoConfig": {
        "PessimisticLock": false // or true
    }
}

More documentation (Sharpino gitbook)

Product Compatible and additional computed target framework versions.
.NET 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. 
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.1.3 0 5/12/2024
2.1.2 46 5/10/2024
2.1.1 42 5/9/2024
2.1.0 45 5/8/2024
2.0.7 81 5/6/2024
2.0.6 81 5/4/2024
2.0.5 48 5/3/2024
2.0.4 37 5/3/2024
2.0.3 35 5/3/2024
2.0.2 36 5/3/2024
2.0.1 33 5/2/2024
2.0.0 39 5/2/2024
1.6.6 76 4/29/2024
1.6.5 76 4/28/2024
1.6.4 73 4/28/2024
1.6.3 83 4/25/2024
1.6.2 91 4/23/2024
1.6.1 84 4/21/2024
1.6.0 99 4/6/2024
1.5.9 143 3/17/2024
1.5.8 150 3/11/2024
1.5.7 136 3/10/2024
1.5.6 179 3/4/2024
1.5.5 182 3/3/2024
1.5.4 181 2/26/2024
1.5.3 226 2/25/2024
1.5.2 193 2/18/2024
1.5.1 241 2/7/2024
1.5.0 217 2/1/2024
1.4.9 257 1/26/2024
1.4.8 259 1/25/2024
1.4.7 330 1/2/2024
1.4.6 353 12/19/2023
1.4.5 354 12/19/2023
1.4.4 386 12/14/2023
1.4.3 361 12/13/2023
1.4.1 411 12/9/2023
1.4.0 388 12/8/2023
1.3.9 429 12/1/2023
1.3.8 445 11/29/2023
1.3.6 415 11/29/2023
1.3.4 417 11/27/2023
1.3.3 430 11/27/2023
1.3.2 424 11/16/2023
1.3.1 400 11/15/2023
1.3.0 404 11/9/2023
1.3.0-beta 369 11/9/2023
1.2.8 397 11/6/2023
1.2.7 405 11/5/2023
1.2.6 439 11/3/2023
1.2.5 431 11/2/2023
1.2.4 454 10/21/2023
1.2.3 453 10/14/2023
1.2.2 420 10/13/2023
1.2.0 433 10/13/2023
1.1.0 455 10/7/2023
1.0.2 437 9/20/2023
1.0.1 474 9/12/2023
1.0.0 1,620 9/12/2023