From b1adfe98d822eda922bab3e2901a86784c46b72b Mon Sep 17 00:00:00 2001 From: Oskar Dudycz Date: Thu, 2 May 2024 08:04:49 +0200 Subject: [PATCH] Removed Marten references --- .../Core/Marten/DocumentSessionExtensions.cs | 6 +++--- .../Mutable/ShoppingCarts/Api.cs | 4 ++-- .../Core/Marten/DocumentSessionExtensions.cs | 10 ++++------ .../Mutable/ShoppingCarts/Api.cs | 4 ++-- .../Core/Marten/DocumentSessionExtensions.cs | 17 +++++++---------- .../Mutable/ShoppingCarts/Api.cs | 4 ++-- .../09-ApplicationLogic.EventStoreDB.csproj | 4 +--- .../09-ApplicationLogic.EventStoreDB/Program.cs | 2 -- .../Core/Marten/DocumentSessionExtensions.cs | 6 +++--- .../Mutable/ShoppingCarts/Api.cs | 2 +- 10 files changed, 25 insertions(+), 34 deletions(-) diff --git a/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs b/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs index f5369263c..c8f370738 100644 --- a/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs +++ b/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs @@ -5,9 +5,9 @@ namespace ApplicationLogic.Marten.Core.Marten; public static class DocumentSessionExtensions { - public static Task Add(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct) - where T : class - => throw new NotImplementedException("Document Session Extensions not implemented!"); + public static Task Add(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct) + where T : class, IAggregate => + throw new NotImplementedException("Document Session Extensions not implemented!"); public static Task Add(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct) where T : class diff --git a/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs b/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs index be7b18493..670f6f311 100644 --- a/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs +++ b/Workshops/IntroductionToEventSourcing/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs @@ -25,8 +25,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a { var shoppingCartId = CombGuidIdGeneration.NewGuid(); - await session.Add(shoppingCartId, - MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct); + await session.Add(shoppingCartId, + MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct); return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId); } diff --git a/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs b/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs index 52f71930e..c32f7242f 100644 --- a/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs +++ b/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs @@ -6,12 +6,10 @@ namespace OptimisticConcurrency.Core.Marten; public static class DocumentSessionExtensions { - public static Task Add(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct) - where T : class - { - documentSession.Events.StartStream(id, @event); - return documentSession.SaveChangesAsync(token: ct); - } + public static Task Add(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct) + where T : class, IAggregate => + documentSession.Add(id, aggregate.DequeueUncommittedEvents(), ct); + public static Task Add(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct) where T : class diff --git a/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs b/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs index 5198c759a..7e8b5bb79 100644 --- a/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs +++ b/Workshops/IntroductionToEventSourcing/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs @@ -28,8 +28,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a { var shoppingCartId = CombGuidIdGeneration.NewGuid(); - await session.Add(shoppingCartId, - MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct); + await session.Add(shoppingCartId, + MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct); return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId); } diff --git a/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs b/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs index d51da9ae2..6d19241d4 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs +++ b/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Core/Marten/DocumentSessionExtensions.cs @@ -6,12 +6,9 @@ namespace ApplicationLogic.Marten.Core.Marten; public static class DocumentSessionExtensions { - public static Task Add(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct) - where T : class - { - documentSession.Events.StartStream(id, @event); - return documentSession.SaveChangesAsync(token: ct); - } + public static Task Add(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct) + where T : class, IAggregate => + documentSession.Add(id, aggregate.DequeueUncommittedEvents(), ct); public static Task Add(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct) where T : class @@ -35,10 +32,10 @@ public static Task GetAndUpdate( Action handle, CancellationToken ct ) where T : class, IAggregate => - documentSession.Events.WriteToAggregate(id, stream => + documentSession.GetAndUpdate(id, state => { - var aggregate = stream.Aggregate ?? throw NotFoundException.For(id); - handle(aggregate); - stream.AppendMany(aggregate.DequeueUncommittedEvents()); + handle(state); + var events = state.DequeueUncommittedEvents(); + return events; }, ct); } diff --git a/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs b/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs index be7b18493..670f6f311 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs +++ b/Workshops/IntroductionToEventSourcing/Solved/08-ApplicationLogic.Marten/Mutable/ShoppingCarts/Api.cs @@ -25,8 +25,8 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a { var shoppingCartId = CombGuidIdGeneration.NewGuid(); - await session.Add(shoppingCartId, - MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct); + await session.Add(shoppingCartId, + MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct); return Created($"/api/mutable/clients/{clientId}/shopping-carts/{shoppingCartId}", shoppingCartId); } diff --git a/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/09-ApplicationLogic.EventStoreDB.csproj b/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/09-ApplicationLogic.EventStoreDB.csproj index cdf38ea57..b156a83cb 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/09-ApplicationLogic.EventStoreDB.csproj +++ b/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/09-ApplicationLogic.EventStoreDB.csproj @@ -9,10 +9,8 @@ - - - + diff --git a/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/Program.cs b/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/Program.cs index 94b2125bc..351e1cb2a 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/Program.cs +++ b/Workshops/IntroductionToEventSourcing/Solved/09-ApplicationLogic.EventStoreDB/Program.cs @@ -2,9 +2,7 @@ using ApplicationLogic.EventStoreDB.Immutable.ShoppingCarts; using ApplicationLogic.EventStoreDB.Mixed.ShoppingCarts; using ApplicationLogic.EventStoreDB.Mutable.ShoppingCarts; -using Marten; using Microsoft.AspNetCore.Diagnostics; -using Oakton; var builder = WebApplication.CreateBuilder(args); diff --git a/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs b/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs index 7da1d7a7f..032432af3 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs +++ b/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Core/Marten/DocumentSessionExtensions.cs @@ -6,9 +6,9 @@ namespace OptimisticConcurrency.Core.Marten; public static class DocumentSessionExtensions { - public static Task Add(this IDocumentSession documentSession, Guid id, object @event, CancellationToken ct) - where T : class => - documentSession.Add(id, [@event], ct); + public static Task Add(this IDocumentSession documentSession, Guid id, T aggregate, CancellationToken ct) + where T : class, IAggregate => + documentSession.Add(id, aggregate.DequeueUncommittedEvents(), ct); public static async Task Add(this IDocumentSession documentSession, Guid id, object[] events, CancellationToken ct) where T : class diff --git a/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs b/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs index c69db679d..ebd58548b 100644 --- a/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs +++ b/Workshops/IntroductionToEventSourcing/Solved/10-OptimisticConcurrency.Marten/Mutable/ShoppingCarts/Api.cs @@ -31,7 +31,7 @@ public static WebApplication ConfigureMutableShoppingCarts(this WebApplication a var shoppingCartId = CombGuidIdGeneration.NewGuid(); var nextExpectedVersion = await session.Add(shoppingCartId, - MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now).DequeueUncommittedEvents(), ct); + MutableShoppingCart.Open(shoppingCartId, clientId.NotEmpty(), Now), ct); context.SetResponseEtag(nextExpectedVersion);