Skip to content
This repository was archived by the owner on May 12, 2026. It is now read-only.

Commit 7e260a9

Browse files
Square refactor
1 parent f0e2361 commit 7e260a9

42 files changed

Lines changed: 981 additions & 483 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Alidade.AppHost/Alidade.AppHost.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Aspire.AppHost.Sdk/13.2.3">
1+
<Project Sdk="Aspire.AppHost.Sdk/13.2.4">
22
<PropertyGroup>
33
<OutputType>Exe</OutputType>
44
<UserSecretsId>453dcf52-98c0-439a-b464-4f576ce577f1</UserSecretsId>

Alidade.Core/AlidadeCoreModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Alidade.Core.Consts;
21
using Autofac;
32
using NetTopologySuite.Geometries;
43

Alidade.Core/Models/CQRS/Response/CommandResult.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text.Json.Serialization;
2-
31
namespace Alidade.Core.Models.CQRS.Response;
42

53
/// <summary>

Alidade.Core/Models/CQRS/Response/QueryResult.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text.Json.Serialization;
2-
31
namespace Alidade.Core.Models.CQRS.Response;
42

53
/// <summary>
@@ -25,6 +23,11 @@ private QueryResult() { }
2523
Success = false,
2624
FailReason = failureReason
2725
};
26+
27+
/// <summary>
28+
/// Creates a success response, used to work around a C# limitation with interfaces.
29+
/// </summary>
30+
public static QueryResult<TResult> Pass(TResult result) => result;
2831
#pragma warning restore CA1000
2932

3033
/// <summary>
@@ -47,9 +50,17 @@ public static implicit operator QueryResult<TResult>(TResult? result)
4750
{
4851
if (result is null)
4952
{
50-
return new() { Success = false, FailReason = "Result is null" };
53+
return new()
54+
{
55+
Success = false,
56+
FailReason = "Result is null"
57+
};
5158
}
5259

53-
return new() { Success = true, Result = result };
60+
return new()
61+
{
62+
Success = true,
63+
Result = result
64+
};
5465
}
5566
}

Alidade.Core/Models/CQRS/Response/ResultBase.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.Text.Json.Serialization;
2-
31
namespace Alidade.Core.Models.CQRS.Response;
42

53
/// <summary>

Alidade.Core/PipelineBehaviors/CommandBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public sealed class CommandBehavior<TRequest>(ILogger<CommandBehavior<TRequest>>
88
protected override bool GetResult(CommandResult response) => response.Success;
99

1010
/// <inheritdoc />
11-
protected override CommandResult GetGenericFailedResponse() => CommandResult.Fail();
11+
protected override CommandResult GetGenericFailedResponse(string? failReason = null) => CommandResult.Fail(failReason);
1212
}

Alidade.Core/PipelineBehaviors/NotificationBehavior.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public async Task Handle(TNotification notification, CancellationToken cancellat
2828
{
2929
await inner.Handle(notification, cancellationToken);
3030
}
31+
catch (OperationCanceledException)
32+
{
33+
logger.LogInformation("Request cancelled [{TypeName}]", typeof(TNotification).FullName);
34+
}
3135
catch (Exception e)
3236
{
3337
logger.LogError(e, "Uncaught Exception [{NotificationName}] | ExceptionMessage = {Message}",

Alidade.Core/PipelineBehaviors/PipelineBehaviorBase.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public abstract class PipelineBehaviorBase<TRequest, TResponse>(ILogger<Pipeline
1616
/// <summary>
1717
/// Generates a failure response for the given type.
1818
/// </summary>
19-
protected abstract TResponse GetGenericFailedResponse();
19+
protected abstract TResponse GetGenericFailedResponse(string? failReason = null);
2020

2121
/// <inheritdoc />
2222
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
@@ -38,12 +38,17 @@ public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TRe
3838
{
3939
response = await next(cancellationToken);
4040
}
41+
catch (OperationCanceledException)
42+
{
43+
logger.LogInformation("Request cancelled [{TypeName}]", typeof(TRequest).FullName);
44+
return GetGenericFailedResponse("Operation cancelled.");
45+
}
4146
catch (Exception e)
4247
{
4348
logger.LogError(e, "Uncaught Exception [{RequestName}] | ExceptionMessage = {Message}",
4449
typeof(TRequest).FullName, e.Message);
4550
exception = e;
46-
response = GetGenericFailedResponse();
51+
response = GetGenericFailedResponse($"Uncaught exception from: {typeof(TRequest).FullName}");
4752
}
4853

4954
bool success = GetResult(response);

Alidade.Core/PipelineBehaviors/QueryBehavior.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ public sealed class QueryBehavior<TRequest, TValue>(ILogger<QueryBehavior<TReque
88
protected override bool GetResult(QueryResult<TValue> response) => response.Success;
99

1010
/// <inheritdoc />
11-
protected override QueryResult<TValue> GetGenericFailedResponse() => QueryResult<TValue>.Fail();
11+
protected override QueryResult<TValue> GetGenericFailedResponse(string? failReason = null) => QueryResult<TValue>.Fail(failReason);
1212
}

Alidade.Osm/AlidadeOsmModule.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using Alidade.Osm.Services;
21
using Autofac;
32

43
namespace Alidade.Osm;

0 commit comments

Comments
 (0)