You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently came up with the idea of creating a source code generator for aggregates because I got tired of writing repetitive boilerplate code.
Let's say we have the following aggregate:
publicclassOrderAggregate(OrderAggregateIdid):AggregateRoot<OrderAggregate,OrderAggregateId>(id){publicTaskDoSomething(){// Some code}}publicclassOrderAggregateId(stringvalue):Identity<OrderAggregateId>(value);
With source generators, we can omit the type declarations, skip the source ID, and avoid the cancellation token:
awaitstore.UpdateAsync(id,
order =>order.DoSomething(),cancellationToken);
The source code generator creates the following extension method for IAggregateStore
publicstaticclassIAggregateStoreExtensions{publicstaticTask<IReadOnlyCollection<IDomainEvent>>UpdateAsync(thisIAggregateStoreaggregateStore,OrderAggregateIdid,Func<OrderAggregate,Task>update,CancellationTokencancellationToken)=>aggregateStore.UpdateAsync<OrderAggregate,OrderAggregateId>(id,SourceId.New,(aggregate,_)=>update(aggregate),cancellationToken);// other code}
What do you think about adding something like this to EventFlow?
Seems simple enough and I'm all for making it easier for developers. Only minor change is that the class should properly be named AggregateStoreExtensions to follow the existing code.
Hi,
I recently came up with the idea of creating a source code generator for aggregates because I got tired of writing repetitive boilerplate code.
Let's say we have the following aggregate:
To update the aggregate, we usually write this
With source generators, we can omit the type declarations, skip the source ID, and avoid the cancellation token:
The source code generator creates the following extension method for
IAggregateStore
What do you think about adding something like this to EventFlow?
You can see the full example here.
The text was updated successfully, but these errors were encountered: