From 0a5408fd61d2dc0313a6b8b941a8b434bf7bdcff Mon Sep 17 00:00:00 2001 From: Corstian Boerman Date: Tue, 10 Dec 2024 14:09:29 +0100 Subject: [PATCH] feat: add an abort operation on aggregate handlers to facilitate the implementation of distributed commit protocols --- .../Grains/AbstractAggregateHandlerGrain.cs | 8 +++++++- .../Abstractions/Aggregate/IAggregateHandler.cs | 10 +++++++++- .../Aggregate/DefaultAggregateHandler.cs | 8 +++++++- .../Scenarios/_0004__aggregate_interfaces.cs | 9 ++++++--- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/Whaally.Domain.Infrastructure.OrleansHost/Grains/AbstractAggregateHandlerGrain.cs b/src/Whaally.Domain.Infrastructure.OrleansHost/Grains/AbstractAggregateHandlerGrain.cs index 17e8b6f..b014b22 100644 --- a/src/Whaally.Domain.Infrastructure.OrleansHost/Grains/AbstractAggregateHandlerGrain.cs +++ b/src/Whaally.Domain.Infrastructure.OrleansHost/Grains/AbstractAggregateHandlerGrain.cs @@ -1,4 +1,5 @@ -using FluentResults; +using System.Diagnostics; +using FluentResults; using Microsoft.Extensions.Logging; using Orleans.Concurrency; using Orleans.EventSourcing; @@ -97,6 +98,11 @@ public async Task Apply(IEventEnvelope eventEnvelope) return Result.Ok(); } + public Task Abort(ActivityContext context) + { + throw new NotImplementedException(); + } + [ReadOnly] public Task Snapshot() where TSnapshot : ISnapshot { diff --git a/src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs b/src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs index 655f1bb..2dcf983 100644 --- a/src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs +++ b/src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs @@ -1,4 +1,5 @@ -using FluentResults; +using System.Diagnostics; +using FluentResults; namespace Whaally.Domain.Abstractions; @@ -51,6 +52,13 @@ public Task Apply(params IEvent[] events) => Apply(new EventEnvelope( new EventMetadata(), events)); + + /// + /// Allows abortion of a running transaction based on the context it is part of + /// + /// + /// + public Task Abort(ActivityContext context); public Task Snapshot() where TSnapshot : ISnapshot; diff --git a/src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs b/src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs index 7e981af..676e77f 100644 --- a/src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs +++ b/src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs @@ -1,4 +1,5 @@ -using FluentResults; +using System.Diagnostics; +using FluentResults; using Microsoft.Extensions.DependencyInjection; using Whaally.Domain.Abstractions; @@ -150,6 +151,11 @@ public async Task Apply(IEventEnvelope eventEnvelope) return Result.Ok(); } + public Task Abort(ActivityContext context) + { + throw new NotImplementedException(); + } + public Task Snapshot() where TSnapshot : ISnapshot => Task.FromResult( diff --git a/tests/Whaally.Domain.Tests/Scenarios/_0004__aggregate_interfaces.cs b/tests/Whaally.Domain.Tests/Scenarios/_0004__aggregate_interfaces.cs index fdfb0d0..87f21c1 100644 --- a/tests/Whaally.Domain.Tests/Scenarios/_0004__aggregate_interfaces.cs +++ b/tests/Whaally.Domain.Tests/Scenarios/_0004__aggregate_interfaces.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using FluentAssertions; using FluentResults; using Microsoft.Extensions.DependencyInjection; @@ -8,12 +9,12 @@ namespace Whaally.Domain.Tests.Scenarios; public class _0004__aggregate_interfaces { public interface ITestAggregate : IAggregate; - + public class TestImplementation : ITestAggregate; // Commands public class TestCommand : ICommand; - + public class TestCommandHandler : ICommandHandler { public IResultBase Evaluate(ICommandHandlerContext context, TestCommand command) @@ -40,6 +41,8 @@ public Task> Evaluate(params ICommandEnvelope[] comman => throw new NotImplementedException(); public Task Apply(params IEventEnvelope[] events) => throw new NotImplementedException(); + public Task Abort(ActivityContext context) + => throw new NotImplementedException(); public Task Snapshot() where TSnapshot : ISnapshot => throw new NotImplementedException(); } @@ -90,4 +93,4 @@ public void CanCreateNewDefaultAggregateHandler() config.AggregateFactory = _ => new TestAggregateFactory(); }) .BuildServiceProvider(), ""); -} \ No newline at end of file +}