11using EventStore . Client ;
2- using Kurrent . Client . Core . Serialization ;
32using Kurrent . Client . Streams . GettingState ;
43
54namespace Kurrent . Client . Streams . DecisionMaking ;
65
76public interface IAggregateStore < TAggregate , TEvent >
87 where TAggregate : IAggregate < TEvent > {
9- Task < StateAtPointInTime < TAggregate > > Get (
8+ Task < StateAtPointInTime < TAggregate > > GetAsync (
109 string streamName ,
10+ GetStreamStateOptions < TAggregate > ? getStreamStateOptions ,
1111 CancellationToken ct = default
1212 ) ;
1313
@@ -36,66 +36,6 @@ Task<IWriteResult> HandleAsync(
3636public interface IAggregateStore < TAggregate > : IAggregateStore < TAggregate , object >
3737 where TAggregate : IAggregate < object > ;
3838
39- public static class AggregateStoreExtensions {
40- public static Task < IWriteResult > AddAsync < TAggregate , TEvent > (
41- this IAggregateStore < TAggregate , TEvent > aggregateStore ,
42- string streamName ,
43- TAggregate aggregate ,
44- CancellationToken ct = default
45- ) where TAggregate : IAggregate < TEvent > =>
46- aggregateStore . AddAsync (
47- streamName ,
48- aggregate ,
49- new AppendToStreamOptions { ExpectedStreamState = StreamState . NoStream } ,
50- ct
51- ) ;
52-
53- public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
54- this IAggregateStore < TAggregate , TEvent > aggregateStore ,
55- string streamName ,
56- Func < TAggregate , CancellationToken , ValueTask > handle ,
57- CancellationToken ct = default
58- ) where TAggregate : IAggregate < TEvent > =>
59- aggregateStore . HandleAsync (
60- streamName ,
61- handle ,
62- new DecideOptions < TAggregate > ( ) ,
63- ct
64- ) ;
65-
66- public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
67- this IAggregateStore < TAggregate , TEvent > aggregateStore ,
68- string streamName ,
69- Action < TAggregate > handle ,
70- CancellationToken ct = default
71- ) where TAggregate : IAggregate < TEvent > =>
72- aggregateStore . HandleAsync (
73- streamName ,
74- ( state , _ ) => {
75- handle ( state ) ;
76- return new ValueTask ( ) ;
77- } ,
78- new DecideOptions < TAggregate > ( ) ,
79- ct
80- ) ;
81-
82- public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
83- this IAggregateStore < TAggregate , TEvent > aggregateStore ,
84- string streamName ,
85- Action < TAggregate > handle ,
86- DecideOptions < TAggregate > ? decideOption ,
87- CancellationToken ct = default
88- ) where TAggregate : IAggregate < TEvent > =>
89- aggregateStore . HandleAsync (
90- streamName ,
91- ( state , _ ) => {
92- handle ( state ) ;
93- return new ValueTask ( ) ;
94- } ,
95- decideOption ,
96- ct
97- ) ;
98- }
9939
10040public class AggregateStoreOptions < TState > where TState : notnull {
10141#if NET48
@@ -111,8 +51,17 @@ public class AggregateStore<TAggregate, TEvent>(KurrentClient client, AggregateS
11151 : IAggregateStore < TAggregate , TEvent >
11252 where TAggregate : IAggregate < TEvent >
11353 where TEvent : notnull {
114- public virtual Task < StateAtPointInTime < TAggregate > > Get ( string streamName , CancellationToken ct = default ) =>
115- client . GetStateAsync ( streamName , options . StateBuilder , ct ) ;
54+ public virtual Task < StateAtPointInTime < TAggregate > > GetAsync (
55+ string streamName ,
56+ GetStreamStateOptions < TAggregate > ? getStreamStateOptions ,
57+ CancellationToken ct = default
58+ ) =>
59+ client . GetStateAsync (
60+ streamName ,
61+ options . StateBuilder ,
62+ getStreamStateOptions ?? options . DecideOptions ? . GetStateOptions ,
63+ ct
64+ ) ;
11665
11766 public virtual Task < IWriteResult > AddAsync (
11867 string streamName ,
@@ -173,3 +122,71 @@ public virtual Task<IWriteResult> HandleAsync(
173122public class AggregateStore < TAggregate > ( KurrentClient client , AggregateStoreOptions < TAggregate > options )
174123 : AggregateStore < TAggregate , object > ( client , options ) , IAggregateStore < TAggregate >
175124 where TAggregate : IAggregate < object > ;
125+
126+ public static class AggregateStoreExtensions {
127+ public static Task < StateAtPointInTime < TAggregate > > GetAsync < TAggregate , TEvent > (
128+ this IAggregateStore < TAggregate , TEvent > aggregateStore ,
129+ string streamName ,
130+ CancellationToken ct = default
131+ ) where TAggregate : IAggregate < TEvent > =>
132+ aggregateStore . GetAsync ( streamName , null , ct ) ;
133+
134+ public static Task < IWriteResult > AddAsync < TAggregate , TEvent > (
135+ this IAggregateStore < TAggregate , TEvent > aggregateStore ,
136+ string streamName ,
137+ TAggregate aggregate ,
138+ CancellationToken ct = default
139+ ) where TAggregate : IAggregate < TEvent > =>
140+ aggregateStore . AddAsync (
141+ streamName ,
142+ aggregate ,
143+ new AppendToStreamOptions { ExpectedStreamState = StreamState . NoStream } ,
144+ ct
145+ ) ;
146+
147+ public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
148+ this IAggregateStore < TAggregate , TEvent > aggregateStore ,
149+ string streamName ,
150+ Func < TAggregate , CancellationToken , ValueTask > handle ,
151+ CancellationToken ct = default
152+ ) where TAggregate : IAggregate < TEvent > =>
153+ aggregateStore . HandleAsync (
154+ streamName ,
155+ handle ,
156+ new DecideOptions < TAggregate > ( ) ,
157+ ct
158+ ) ;
159+
160+ public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
161+ this IAggregateStore < TAggregate , TEvent > aggregateStore ,
162+ string streamName ,
163+ Action < TAggregate > handle ,
164+ CancellationToken ct = default
165+ ) where TAggregate : IAggregate < TEvent > =>
166+ aggregateStore . HandleAsync (
167+ streamName ,
168+ ( state , _ ) => {
169+ handle ( state ) ;
170+ return new ValueTask ( ) ;
171+ } ,
172+ new DecideOptions < TAggregate > ( ) ,
173+ ct
174+ ) ;
175+
176+ public static Task < IWriteResult > HandleAsync < TAggregate , TEvent > (
177+ this IAggregateStore < TAggregate , TEvent > aggregateStore ,
178+ string streamName ,
179+ Action < TAggregate > handle ,
180+ DecideOptions < TAggregate > ? decideOption ,
181+ CancellationToken ct = default
182+ ) where TAggregate : IAggregate < TEvent > =>
183+ aggregateStore . HandleAsync (
184+ streamName ,
185+ ( state , _ ) => {
186+ handle ( state ) ;
187+ return new ValueTask ( ) ;
188+ } ,
189+ decideOption ,
190+ ct
191+ ) ;
192+ }
0 commit comments