This is just an braindrump and rolling gist that reflect the thought about POCO support for Ncqrs.
- Contain typed event handling methods like
OnCustomerNameChanged(NameChanged e)
that update internal state. - Contains a Guid ID property. This will hold the event source id.
- Contains one ctor for 'new' instances that only accepts an Func callback.
- Contains one ctor to support loading from history. This ctor has two parameters. On Func callback and an Guid value with the existing id.
So minimal code is:
public class TestPocoAggregateRoot
{
private readonly Action<ISourcedEvent> ApplyEvent;
public Guid Id { get; private set; }
private int _state;
public TestPocoAggregateRoot(Guid id, Action<ISourcedEvent> applyEvent) : this(applyEvent)
{
Id = id;
}
public TestPocoAggregateRoot(Action<ISourcedEvent> applyEvent)
{
ApplyEvent = applyEvent;
}
public void DoSomething(int arguments)
{
ApplyEvent(new SomethingDone{ Value = arguments * 42 });
}
protected void OnSomethingDone(SomethingDone evnt)
{
_state += evnt.Value;
}
}
public class SomethingDone : SourcedEvent
{
public int Value { get; set; }
}