Created
October 22, 2012 20:26
-
-
Save yreynhout/3933919 to your computer and use it in GitHub Desktop.
Seek simplicity & loose coupling between aggregate root and event builder.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IMessageBuilder { | |
| object Build(); | |
| } | |
| public interface IEventBuilder : IMessageBuilder { | |
| IMessageBuilder IdentifiedBy(Guid id, int version); | |
| } | |
| public abstract class AggregateRootEntity { | |
| //... | |
| protected void ApplyEvent(IEventBuilder builder) { | |
| //Explicit builder contract | |
| var @event = builder.IdentifiedBy(_id, _version++).Build(); | |
| Play(@event); | |
| Record(@event); | |
| } | |
| void Play(object @event) { _handlers[@event.GetType()](@event); } | |
| void Record(object @event) { _changes.Add(@event); } | |
| //... | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public abstract class AggregateRootEntity { | |
| //... | |
| protected void ApplyEvent(Func<Guid, int, object> builder) { | |
| //Func-style builder contract | |
| var @event = builder(_id, _version++); | |
| Play(@event); | |
| Record(@event); | |
| } | |
| void Play(object @event) { _handlers[@event.GetType()](@event); } | |
| void Record(object @event) { _changes.Add(@event); } | |
| //... | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment