Events

Events are discriminated unions (DU) with cases associated with members of the context that end up in adding/updating/deleting/ entities.

When we process an event it returns a new state or an error:

    type Event<'A> =
        abstract member Process: 'A -> Result<'A, string>

The 'A is the generic context or aggregate type, the event is associated with.

This is an example of a concrete implementation of an event related to the TodoCluster members Add and Remove.

So, for example, the TodoAdded event is associated with the AddTodo member. The Process member of the event is implemented by calling the related clusters member.

    type TodoEvent =
        | TodoAdded of Todo
        | TodoRemoved of Guid
            interface Event<TodosCluster> with
                member this.Process (x: TodosContext ) =
                    match this with
                    | TodoAdded (t: Todo) -> 
                        x.AddTodo t
                    | TodoRemoved (g: Guid) -> 
                        x.RemoveTodo g

Source code: Events.fs