Skip to content

Instantly share code, notes, and snippets.

@CraftyFella
Last active July 22, 2021 15:23
Show Gist options
  • Save CraftyFella/613effd95f0a5d9cfc87f7626c176cd7 to your computer and use it in GitHub Desktop.
Save CraftyFella/613effd95f0a5d9cfc87f7626c176cd7 to your computer and use it in GitHub Desktop.
Marten.cs
public abstract record StreamName;
public record AnEvent(string Description) : StreamName;
public static class DocumentStoreFactory
{
public static DocumentStore Create()
{
const string connectionString =
"PORT = 5432; HOST = 127.0.0.1; TIMEOUT = 15; POOLING = True; MINPOOLSIZE = 1; MAXPOOLSIZE = 100; COMMANDTIMEOUT = 20; DATABASE = 'postgres'; PASSWORD = 'Password12!'; USER ID = 'postgres'";
var store = DocumentStore.For(options =>
{
options.Connection(connectionString);
options.AutoCreateSchemaObjects = AutoCreate.None;
options.DatabaseSchemaName = "EventStore";
options.Events.DatabaseSchemaName = "EventStore";
options.Events.AddEventType(typeof(AnEvent));
options.Events.AsyncProjections.AggregateStreamsWith<Counter>();
});
return store;
}
}
public class Counter
{
private int _total;
public void Apply(AnEvent @event)
{
Console.WriteLine($"Applying Event {@event}");
_total++;
}
public Guid Id { get; set; }
public override string ToString()
{
return $"Total is {_total}";
}
}
var documentStore = DocumentStoreFactory.Create();
using var daemon = documentStore.BuildProjectionDaemon();
daemon.StartAll();
await daemon.WaitForNonStaleResults().ConfigureAwait(false);
await daemon.StopAll().ConfigureAwait(false);
// Caused `relation "eventstore.mt_doc_counter" does not exist`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment