Skip to content

Commit b37022b

Browse files
committed
Allow passing null as postgres options and use the default
1 parent da47a69 commit b37022b

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/Postgres/src/Eventuous.Postgresql/PostgresStore.cs

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Eventuous.Diagnostics;
88
using Eventuous.Postgresql.Extensions;
99
using Eventuous.Tools;
10+
using Microsoft.Extensions.Options;
1011
using Npgsql;
1112
using NpgsqlTypes;
1213

@@ -26,16 +27,24 @@ public class PostgresStore : IEventStore {
2627

2728
public PostgresStore(
2829
GetPostgresConnection getConnection,
29-
PostgresStoreOptions options,
30+
PostgresStoreOptions? options,
3031
IEventSerializer? serializer = null,
3132
IMetadataSerializer? metaSerializer = null
3233
) {
3334
_serializer = serializer ?? DefaultEventSerializer.Instance;
3435
_metaSerializer = metaSerializer ?? DefaultMetadataSerializer.Instance;
3536
_getConnection = Ensure.NotNull(getConnection, "Connection factory");
36-
_schema = new Schema(options.Schema);
37+
var pgOptions = options ?? new PostgresStoreOptions();
38+
_schema = new Schema(pgOptions.Schema);
3739
}
3840

41+
public PostgresStore(
42+
GetPostgresConnection getConnection,
43+
IOptions<PostgresStoreOptions> options,
44+
IEventSerializer? serializer = null,
45+
IMetadataSerializer? metaSerializer = null
46+
) : this(getConnection, options.Value, serializer, metaSerializer) { }
47+
3948
const string ContentType = "application/json";
4049

4150
async Task<NpgsqlConnection> OpenConnection(CancellationToken cancellationToken) {
@@ -133,15 +142,13 @@ public Task TruncateStream(
133142
StreamTruncatePosition truncatePosition,
134143
ExpectedStreamVersion expectedVersion,
135144
CancellationToken cancellationToken
136-
)
137-
=> throw new NotImplementedException();
145+
) => throw new NotImplementedException();
138146

139147
public Task DeleteStream(
140148
StreamName stream,
141149
ExpectedStreamVersion expectedVersion,
142150
CancellationToken cancellationToken
143-
)
144-
=> throw new NotImplementedException();
151+
) => throw new NotImplementedException();
145152

146153
StreamEvent ToStreamEvent(PersistedEvent evt) {
147154
var deserialized = _serializer.DeserializeEvent(
@@ -162,9 +169,14 @@ StreamEvent ToStreamEvent(PersistedEvent evt) {
162169
_ => throw new Exception("Unknown deserialization result")
163170
};
164171

165-
StreamEvent AsStreamEvent(object payload)
166-
=> new(evt.MessageId, payload, meta ?? new Metadata(), ContentType, evt.StreamPosition);
172+
StreamEvent AsStreamEvent(object payload) => new(
173+
evt.MessageId,
174+
payload,
175+
meta ?? new Metadata(),
176+
ContentType,
177+
evt.StreamPosition
178+
);
167179
}
168180
}
169181

170-
record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata);
182+
record NewPersistedEvent(Guid MessageId, string MessageType, string JsonData, string? JsonMetadata);

0 commit comments

Comments
 (0)