Skip to content

Commit

Permalink
feat: add an abort operation on aggregate handlers to facilitate the …
Browse files Browse the repository at this point in the history
…implementation of distributed commit protocols
  • Loading branch information
corstian committed Dec 10, 2024
1 parent 7559d11 commit 0a5408f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentResults;
using System.Diagnostics;
using FluentResults;
using Microsoft.Extensions.Logging;
using Orleans.Concurrency;
using Orleans.EventSourcing;
Expand Down Expand Up @@ -97,6 +98,11 @@ public async Task<IResultBase> Apply(IEventEnvelope eventEnvelope)
return Result.Ok();
}

public Task Abort(ActivityContext context)
{
throw new NotImplementedException();
}

[ReadOnly]
public Task<TSnapshot> Snapshot<TSnapshot>() where TSnapshot : ISnapshot
{
Expand Down
10 changes: 9 additions & 1 deletion src/Whaally.Domain/Abstractions/Aggregate/IAggregateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentResults;
using System.Diagnostics;
using FluentResults;

namespace Whaally.Domain.Abstractions;

Expand Down Expand Up @@ -51,6 +52,13 @@ public Task<IResultBase> Apply(params IEvent[] events)
=> Apply(new EventEnvelope(
new EventMetadata(),
events));

/// <summary>
/// Allows abortion of a running transaction based on the context it is part of
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public Task Abort(ActivityContext context);

public Task<TSnapshot> Snapshot<TSnapshot>()
where TSnapshot : ISnapshot;
Expand Down
8 changes: 7 additions & 1 deletion src/Whaally.Domain/Aggregate/DefaultAggregateHandler.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using FluentResults;
using System.Diagnostics;
using FluentResults;
using Microsoft.Extensions.DependencyInjection;
using Whaally.Domain.Abstractions;

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

public Task Abort(ActivityContext context)
{
throw new NotImplementedException();
}

public Task<TSnapshot> Snapshot<TSnapshot>()
where TSnapshot : ISnapshot =>
Task.FromResult(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Diagnostics;
using FluentAssertions;
using FluentResults;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -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<ITestAggregate, TestCommand>
{
public IResultBase Evaluate(ICommandHandlerContext<ITestAggregate> context, TestCommand command)
Expand All @@ -40,6 +41,8 @@ public Task<IResult<IEventEnvelope[]>> Evaluate(params ICommandEnvelope[] comman
=> throw new NotImplementedException();
public Task<IResultBase> Apply(params IEventEnvelope[] events)
=> throw new NotImplementedException();
public Task Abort(ActivityContext context)
=> throw new NotImplementedException();
public Task<TSnapshot> Snapshot<TSnapshot>() where TSnapshot : ISnapshot
=> throw new NotImplementedException();
}
Expand Down Expand Up @@ -90,4 +93,4 @@ public void CanCreateNewDefaultAggregateHandler()
config.AggregateFactory = _ => new TestAggregateFactory();
})
.BuildServiceProvider(), "");
}
}

0 comments on commit 0a5408f

Please sign in to comment.