7
7
using Eventuous . Diagnostics ;
8
8
using Eventuous . Postgresql . Extensions ;
9
9
using Eventuous . Tools ;
10
+ using Microsoft . Extensions . Options ;
10
11
using Npgsql ;
11
12
using NpgsqlTypes ;
12
13
@@ -26,16 +27,24 @@ public class PostgresStore : IEventStore {
26
27
27
28
public PostgresStore (
28
29
GetPostgresConnection getConnection ,
29
- PostgresStoreOptions options ,
30
+ PostgresStoreOptions ? options ,
30
31
IEventSerializer ? serializer = null ,
31
32
IMetadataSerializer ? metaSerializer = null
32
33
) {
33
34
_serializer = serializer ?? DefaultEventSerializer . Instance ;
34
35
_metaSerializer = metaSerializer ?? DefaultMetadataSerializer . Instance ;
35
36
_getConnection = Ensure . NotNull ( getConnection , "Connection factory" ) ;
36
- _schema = new Schema ( options . Schema ) ;
37
+ var pgOptions = options ?? new PostgresStoreOptions ( ) ;
38
+ _schema = new Schema ( pgOptions . Schema ) ;
37
39
}
38
40
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
+
39
48
const string ContentType = "application/json" ;
40
49
41
50
async Task < NpgsqlConnection > OpenConnection ( CancellationToken cancellationToken ) {
@@ -133,15 +142,13 @@ public Task TruncateStream(
133
142
StreamTruncatePosition truncatePosition ,
134
143
ExpectedStreamVersion expectedVersion ,
135
144
CancellationToken cancellationToken
136
- )
137
- => throw new NotImplementedException ( ) ;
145
+ ) => throw new NotImplementedException ( ) ;
138
146
139
147
public Task DeleteStream (
140
148
StreamName stream ,
141
149
ExpectedStreamVersion expectedVersion ,
142
150
CancellationToken cancellationToken
143
- )
144
- => throw new NotImplementedException ( ) ;
151
+ ) => throw new NotImplementedException ( ) ;
145
152
146
153
StreamEvent ToStreamEvent ( PersistedEvent evt ) {
147
154
var deserialized = _serializer . DeserializeEvent (
@@ -162,9 +169,14 @@ StreamEvent ToStreamEvent(PersistedEvent evt) {
162
169
_ => throw new Exception ( "Unknown deserialization result" )
163
170
} ;
164
171
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
+ ) ;
167
179
}
168
180
}
169
181
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