SAFE_ES 1.0.4

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

// Install SAFE_ES as a Cake Tool
#tool nuget:?package=SAFE_ES&version=1.0.4

Event sourcing version of SAFE template

I adapted the SAFE Template integrating it into a tiny event sourcing set of utilities I created.

Update: In version 1.0.2 there is an Aggregate containing models and projections (model and projections are equivalent and they implement the same interface). The aggregate works as a decorator for the model and the projections.

I created an aggregate implementing our logic Todos.fs. It is unaware the persistency logic, because I wrap members that are supposed to "change the state" (in a functional way) into commands and events, and then expose the commands in App.fs. To wrap specific domain logic members we need a discriminated union for the Events (in the Todos.fs module) and a discriminated union for commands Commands.fs. What commands do is probing the respective members and return events if they don't return error.

Recap. You create the aggregate, the events, expose them (as in App.fs), and anything else can be reused to implement the business domain.

More details:

  • DbStorage.fs: connect to the database for writing and reading events and snapshots.
  • MemoryStorage.fs: alternative of db, is this one to use in memory data structures to manage events and snapshots.
  • Repository.fs: rely on the storage to:
    1. get the current state.
    1. run commands, generating the corresponding events and storing them.
    1. store and read snapshots
  • EventSourcing.fs: defines abstractions based on interfaces, generics, constraints.

Description:

    1. events must be discriminated Unions implementing the Processable interface, to wrap the members defined in the aggregate Todos.fs.
    1. Commands implement the Executable interface and returns events or error, as in the Commands.fs.
    1. App.fs Exposes the domain logic. Methods present there run command if needed and create snapshots.
    1. How to make upgrades i.e. manage versions: I don't manage versioning yet, but when you add behavior to the aggregate without changing previous behavior then I know that a simple solution is:
      1. when the new version of your root class is ready (i.e. the new version of the todo), then just deploy it, and delete all the snapshots entries in the snapshots table. What will happen is that the snapshot in the new format will be rebuilt, after restart or after an event.
      1. Deploy the part related to new events (Processable), commands (Executable) and App (App.fs exposing the business logic to outside).
      1. Make the new behavior available by extending the interface used by SAFE (i.e. the ITodosApi) and its implementation (todosapi in Server.fs)
    • Basically: under the acceptable assumption that when upgrading we just extend, and not change the aggregate (substitution principle), then any upgrade should not be a problem.

Other "dispatching" logic work in the same way as they original are part of the way the original SAFE example. (i.e. ITodosApi and interface and implementation)

Installation

The ordinary SAFE requirement (as follows) plus a postgres database using the Schema.sql script to create user, database, and tables.

What follows now is the original SAFE doc

SAFE Template

This template can be used to generate a full-stack web application using the SAFE Stack. It was created using the dotnet SAFE Template. If you want to learn more about the template why not start with the quick start guide?

Install pre-requisites

You'll need to install the following pre-requisites in order to build SAFE applications

Starting the application

Before you run the project for the first time only you must install dotnet "local tools" with this command:

dotnet tool restore

To concurrently run the server and the client components in watch mode use the following command:

dotnet run

Then open http://localhost:8080 in your browser.

The build project in root directory contains a couple of different build targets. You can specify them after -- (target name is case-insensitive).

To run concurrently server and client tests in watch mode (you can run this command in parallel to the previous one in new terminal):

dotnet run -- RunTests

Client tests are available under http://localhost:8081 in your browser and server tests are running in watch mode in console.

Finally, there are Bundle and Azure targets that you can use to package your app and deploy to Azure, respectively:

dotnet run -- Bundle
dotnet run -- Azure

SAFE Stack Documentation

If you want to know more about the full Azure Stack and all of it's components (including Azure) visit the official SAFE documentation.

You will find more documentation about the used F# components at the following places:

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

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.0.4 316 4/16/2023
1.0.2 442 2/19/2023
1.0.1 466 2/17/2023
1.0.0 383 2/17/2023

Initial release.