Skip to content

Commit 0a5408f

Browse files
committed
feat: add an abort operation on aggregate handlers to facilitate the implementation of distributed commit protocols
1 parent 7559d11 commit 0a5408f

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

src/Whaally.Domain.Infrastructure.OrleansHost/Grains/AbstractAggregateHandlerGrain.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentResults;
1+
using System.Diagnostics;
2+
using FluentResults;
23
using Microsoft.Extensions.Logging;
34
using Orleans.Concurrency;
45
using Orleans.EventSourcing;
@@ -97,6 +98,11 @@ public async Task<IResultBase> Apply(IEventEnvelope eventEnvelope)
9798
return Result.Ok();
9899
}
99100

101+
public Task Abort(ActivityContext context)
102+
{
103+
throw new NotImplementedException();
104+
}
105+
100106
[ReadOnly]
101107
public Task<TSnapshot> Snapshot<TSnapshot>() where TSnapshot : ISnapshot
102108
{

src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentResults;
1+
using System.Diagnostics;
2+
using FluentResults;
23

34
namespace Whaally.Domain.Abstractions;
45

@@ -51,6 +52,13 @@ public Task<IResultBase> Apply(params IEvent[] events)
5152
=> Apply(new EventEnvelope(
5253
new EventMetadata(),
5354
events));
55+
56+
/// <summary>
57+
/// Allows abortion of a running transaction based on the context it is part of
58+
/// </summary>
59+
/// <param name="context"></param>
60+
/// <returns></returns>
61+
public Task Abort(ActivityContext context);
5462

5563
public Task<TSnapshot> Snapshot<TSnapshot>()
5664
where TSnapshot : ISnapshot;

src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using FluentResults;
1+
using System.Diagnostics;
2+
using FluentResults;
23
using Microsoft.Extensions.DependencyInjection;
34
using Whaally.Domain.Abstractions;
45

@@ -150,6 +151,11 @@ public async Task<IResultBase> Apply(IEventEnvelope eventEnvelope)
150151
return Result.Ok();
151152
}
152153

154+
public Task Abort(ActivityContext context)
155+
{
156+
throw new NotImplementedException();
157+
}
158+
153159
public Task<TSnapshot> Snapshot<TSnapshot>()
154160
where TSnapshot : ISnapshot =>
155161
Task.FromResult(

tests/Whaally.Domain.Tests/Scenarios/_0004__aggregate_interfaces.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics;
12
using FluentAssertions;
23
using FluentResults;
34
using Microsoft.Extensions.DependencyInjection;
@@ -8,12 +9,12 @@ namespace Whaally.Domain.Tests.Scenarios;
89
public class _0004__aggregate_interfaces
910
{
1011
public interface ITestAggregate : IAggregate;
11-
12+
1213
public class TestImplementation : ITestAggregate;
1314

1415
// Commands
1516
public class TestCommand : ICommand;
16-
17+
1718
public class TestCommandHandler : ICommandHandler<ITestAggregate, TestCommand>
1819
{
1920
public IResultBase Evaluate(ICommandHandlerContext<ITestAggregate> context, TestCommand command)
@@ -40,6 +41,8 @@ public Task<IResult<IEventEnvelope[]>> Evaluate(params ICommandEnvelope[] comman
4041
=> throw new NotImplementedException();
4142
public Task<IResultBase> Apply(params IEventEnvelope[] events)
4243
=> throw new NotImplementedException();
44+
public Task Abort(ActivityContext context)
45+
=> throw new NotImplementedException();
4346
public Task<TSnapshot> Snapshot<TSnapshot>() where TSnapshot : ISnapshot
4447
=> throw new NotImplementedException();
4548
}
@@ -90,4 +93,4 @@ public void CanCreateNewDefaultAggregateHandler()
9093
config.AggregateFactory = _ => new TestAggregateFactory();
9194
})
9295
.BuildServiceProvider(), "");
93-
}
96+
}

0 commit comments

Comments
 (0)