Created
June 19, 2011 16:09
-
-
Save marcofranssen/1034436 to your computer and use it in GitHub Desktop.
MergingHandler Example
This file contains 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 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