Last active
August 29, 2015 14:18
-
-
Save perokvist/7eaf14b2b643b40469ff to your computer and use it in GitHub Desktop.
Commit log examples
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 Module | |
{ | |
public static Func<ICommand, Task> Run(CancellationToken token, Subject<IEvent> eventSubject, Action<string> logger) | |
{ | |
const string streamName = "the-stream"; | |
var commitLog = new MessageVaultClientAdapter(new MemoryClient(), logger); | |
var dispatcher = new Dispatcher<ICommand, Task>(); | |
var eventHandlers = new Dispatcher<IEvent, Task>(); | |
var checkpointWriter = new CheckpointWriterAdapter(new MemoryCheckpointReaderWriter()); | |
var repository = new InMemoryStateRepository<State>(); | |
var streamProcessor = new StreamProcessor(commitLog, streamName, checkpointWriter, Serialization.Deserializer(), Console.WriteLine); | |
var eventLog = commitLog.ToStreamPoster(Serialization.Serializer()); | |
dispatcher.Register<IYourAggregateCommand>( | |
command => ApplicationService.Execute( | |
command, | |
id => repository.GetOrCreateAsync(id), | |
state => new YourAggregate(state), | |
aggregate => aggregate.Handle(command), | |
eventLog.ForStream(streamName))); | |
eventHandlers.Register<IEvent>(@event => StateEventHandler.ForAsync(@event, (e, s) => s.When(e), repository)); | |
streamProcessor.Run(token, @event => eventSubject.OnNext(@event)); | |
eventSubject.Subscribe(@event => eventHandlers.Dispatch(@event).Wait(), () => { }, token); | |
return Mixins.WaitForEventsPublished(dispatcher.Dispatch, eventSubject, logger); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment