Last active
July 22, 2021 15:23
-
-
Save CraftyFella/613effd95f0a5d9cfc87f7626c176cd7 to your computer and use it in GitHub Desktop.
Marten.cs
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 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