Skip to content

Instantly share code, notes, and snippets.

@marcofranssen
Created June 19, 2011 16:09
Show Gist options
  • Save marcofranssen/1034436 to your computer and use it in GitHub Desktop.
Save marcofranssen/1034436 to your computer and use it in GitHub Desktop.
MergingHandler Example
public class MergingHandler<T> : Consumes<T>
{
public MergingHandler(Consumes<T> next)
{
}
public void Consume(T message)
{
try
{
BEGIN:
var commit = eventStore.GetEventsSinceVersion(message.AggregateId, message.ExpectedVersion);
next.Handle(message);
foreach(var e in commit)
{
foreach(vat attempted in UnitOfWork.Current.PeekAll())
{
if(ConflictsWith(attempted, e)) throw new RealConcurrencyException();
}
}
UnitOfWork.Current.Commit();
}
catch(ConcurrencyException e) {
goto BEGIN;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment