Super-short example

So how does it actually look when writing an application with Revo?

These few following paragraphs show how could one design super-simple application that can save tasks using event-sourced aggregates and then query them back from a RDBMS.

A little-bit more complete application based on this code, along with some walkthrough, can be found in the Task list app example.

Event

The event that happens when changing a task's name.

public class TodoRenamedEvent : DomainAggregateEvent
{
    public TodoRenamedEvent(string name)
    {
        Name = name;
    }

    public string Name { get; }
}

Aggregate

The task aggregate root.

public class Todo : EventSourcedAggregateRoot
{
    public Todo(Guid id, string name) : base(id)
    {
        Rename(name);
    }
    
    protectedTodo(Guid id) : base(id)
    {
    }

    public string Name { get; private set; }

    public void Rename(string name)
    {
        if (!Name != name)
        {
            Publish(new TodoRenamedEvent(name));
        }
    }
    
    private void Apply(TodoRenamedEvent ev)
    {
        Name = ev.Name;
    }
}

Command and command handler

Command to save a new task.

Read model and projection

Read model and a projection for the event-sourced aggregate.

Query and query handler

Query to read the tasks back from a RDBMS.

ASP.NET Core controller

Or just any arbitrary endpoint from where to send the command and queries from. :)

Finish!

Now you are ready save the TO-DOs to an event store and read them from regular RDBMS read models.

Last updated