Events

An event is an object that, when processed against a specific state of an aggregate or a context, returns a new state or an error:

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

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<Todo> with
                member this.Process (x: TodosContext ) =
                    match this with
                    | TodoAdded (t: Todo) -> 
                        x.AddTodo t
                    | TodoRemoved (g: Guid) -> 
                        x.RemoveTodo g

We may notice that there is a direct association between events and members of the aggregate or context. This may arise a concern when we want to overload members of an aggregate or context (i.e., having multiple members with the same name but different parameters). By overloading the members of an aggregates may make the association between events and members less clear as there is no valid way to express members overloding in the event types directly (would be an invalid DU). A workaround would be easy (create a specific DU for the parameters to express the overloading for example)

Source code: Events.fs