The state of aggregate roots is modified by events. This means that when a aggregate root wants to modify his own state, it creates an event that represent that change and applies it to itself. By applying the event, the state get modified in a event handler this lives inside a aggregate root. With the AggregateRootMappedByConvention class you can easily map methods as event handler by a convention. Here is a little example:

public class MyAggregateRoot : AggregateRootMappedByConvention
{
    private string _barValue;

    public void DoFoo(string bar)
    {
        var evnt = new FooEvent(bar);
        ApplyEvent(evnt);
    }

    // Event handler for FooEvent.
    // Is automaticly mapped since it satisfies the convention.
    private void OnFooEvent(FooEvent evnt)
    {
        _barValue = evnt.BarValue;
    }
}

Last edited May 4, 2010 at 1:40 PM by pjvandesande, version 1

Comments

No comments yet.