diff --git a/src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs b/src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs index 675ac92d..83473b42 100644 --- a/src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs +++ b/src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs @@ -7,6 +7,7 @@ using Eventuous.Diagnostics; using Eventuous.Postgresql.Extensions; using Eventuous.Tools; +using Microsoft.Extensions.Options; using Npgsql; using NpgsqlTypes; @@ -26,16 +27,24 @@ public class PostgresStore : IEventStore { public PostgresStore( GetPostgresConnection getConnection, - PostgresStoreOptions options, + PostgresStoreOptions? options, IEventSerializer? serializer = null, IMetadataSerializer? metaSerializer = null ) { _serializer = serializer ?? DefaultEventSerializer.Instance; _metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance; _getConnection = Ensure.NotNull(getConnection, "Connection factory"); - _schema = new Schema(options.Schema); + var pgOptions = options ?? new PostgresStoreOptions(); + _schema = new Schema(pgOptions.Schema); } + public PostgresStore( + GetPostgresConnection getConnection, + IOptions options, + IEventSerializer? serializer = null, + IMetadataSerializer? metaSerializer = null + ) : this(getConnection, options.Value, serializer, metaSerializer) { } + const string ContentType = "application/json"; async Task OpenConnection(CancellationToken cancellationToken) { @@ -133,15 +142,13 @@ public Task TruncateStream( StreamTruncatePosition truncatePosition, ExpectedStreamVersion expectedVersion, CancellationToken cancellationToken - ) - => throw new NotImplementedException(); + ) => throw new NotImplementedException(); public Task DeleteStream( StreamName stream, ExpectedStreamVersion expectedVersion, CancellationToken cancellationToken - ) - => throw new NotImplementedException(); + ) => throw new NotImplementedException(); StreamEvent ToStreamEvent(PersistedEvent evt) { var deserialized = _serializer.DeserializeEvent( @@ -162,9 +169,14 @@ StreamEvent ToStreamEvent(PersistedEvent evt) { _ => throw new Exception("Unknown deserialization result") }; - StreamEvent AsStreamEvent(object payload) - => new(evt.MessageId, payload, meta ?? new Metadata(), ContentType, evt.StreamPosition); + StreamEvent AsStreamEvent(object payload) => new( + evt.MessageId, + payload, + meta ?? new Metadata(), + ContentType, + evt.StreamPosition + ); } } -record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata); \ No newline at end of file +record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata);