From 68eb9b0f2d15c785e0f3dfb4ac7ff54f93899042 Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 18 Sep 2025 20:25:41 +0000 Subject: [PATCH 1/3] refactor: use file scoped namespaces This PR refactors the codebase to adopt C# file-scoped namespaces across multiple modules, eliminating traditional block-scoped namespace declarations. By converting to file-scoped syntax, we reduce nesting, remove redundant braces, and improve overall readability of each file. - Use File Scoped `namespace`s instead of typical `namespace`s: The code originally declared namespaces with braces and nested indentations, making files longer and less concise. We updated each affected file (including TestData, domain event handlers, request handlers, service interfaces, and the middleware registry) to use the `namespace X;` syntax at the top, removed matching closing braces, and adjusted `using` directives so that all files consistently follow the C# 10 file-scoped namespace convention. > This Autofix was generated by AI. Please review the change before merging. --- CallbackHander.Testing/TestData.cs | 67 +++++++------ .../DomainEventTypesToSilentlyHandle.cs | 82 ++++++++-------- .../IDomainEventTypesToSilentlyHandle.cs | 33 ++++--- .../CallbackHandlerRequestHandler.cs | 85 +++++++++-------- .../Services/ICallbackDomainService.cs | 21 ++--- .../Bootstrapper/MiddlewareRegistry.cs | 94 +++++++++---------- 6 files changed, 189 insertions(+), 193 deletions(-) diff --git a/CallbackHander.Testing/TestData.cs b/CallbackHander.Testing/TestData.cs index a0e1ff1..9e36a31 100644 --- a/CallbackHander.Testing/TestData.cs +++ b/CallbackHander.Testing/TestData.cs @@ -2,50 +2,49 @@ using CallbackHandlers.Models; using Xunit; -namespace CallbackHander.Testing -{ - using CallbackHandler.BusinessLogic.Requests; - using CallbackHandler.CallbackMessageAggregate; +namespace CallbackHander.Testing; - public class TestData - { - public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E"); +using CallbackHandler.BusinessLogic.Requests; +using CallbackHandler.CallbackMessageAggregate; - public static Int32 MessageFormat = 1; +public class TestData +{ + public static Guid CallbackId = Guid.Parse("E82DF060-5717-4F79-B99B-E14C702C8F0E"); - public static String TypeString = "TestTypeString"; + public static Int32 MessageFormat = 1; - public static String CallbackMessage = "Callback message"; + public static String TypeString = "TestTypeString"; - public static String[] Destinations = new[] {"A", "B"}; + public static String CallbackMessage = "Callback message"; - public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29"; - public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C"); - public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29"); + public static String[] Destinations = new[] {"A", "B"}; - public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest => - new CallbackCommands.RecordCallbackRequest(TestData.CallbackId, - TestData.CallbackMessage, - TestData.Destinations, - (MessageFormat)TestData.MessageFormat, - TestData.TypeString, - TestData.Reference); + public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29"; + public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C"); + public static Guid MerchantReference = Guid.Parse("9D20A396-1CF6-45ED-AA7B-DD436318BA29"); - public static CallbackQueries.GetCallbackQuery GetCallbackQuery => - new CallbackQueries.GetCallbackQuery(TestData.CallbackId); + public static CallbackCommands.RecordCallbackRequest RecordCallbackRequest => + new CallbackCommands.RecordCallbackRequest(TestData.CallbackId, + TestData.CallbackMessage, + TestData.Destinations, + (MessageFormat)TestData.MessageFormat, + TestData.TypeString, + TestData.Reference); - public static CallbackMessageAggregate EmptyCallbackMessageAggregate() - { - return new CallbackMessageAggregate(); - } + public static CallbackQueries.GetCallbackQuery GetCallbackQuery => + new CallbackQueries.GetCallbackQuery(TestData.CallbackId); - public static CallbackMessageAggregate RecordedCallbackMessageAggregate() - { - CallbackMessageAggregate aggregate = new(); - aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat, - TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference); + public static CallbackMessageAggregate EmptyCallbackMessageAggregate() + { + return new CallbackMessageAggregate(); + } + + public static CallbackMessageAggregate RecordedCallbackMessageAggregate() + { + CallbackMessageAggregate aggregate = new(); + aggregate.RecordCallback(TestData.CallbackId, TestData.TypeString, (MessageFormat)TestData.MessageFormat, + TestData.CallbackMessage, TestData.Reference, TestData.Destinations, EstateReference, MerchantReference); - return aggregate; - } + return aggregate; } } diff --git a/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs b/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs index c05d1c6..8a8514e 100644 --- a/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs +++ b/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs @@ -1,54 +1,54 @@ -namespace CallbackHandler.BusinessLogic.Common +namespace CallbackHandler.BusinessLogic.Common; + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using Shared.DomainDrivenDesign.EventSourcing; + +[ExcludeFromCodeCoverage] +public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle { - using System; - using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; - using System.Linq; - using Shared.DomainDrivenDesign.EventSourcing; - - [ExcludeFromCodeCoverage] - public class DomainEventTypesToSilentlyHandle : IDomainEventTypesToSilentlyHandle - { - #region Fields + #region Fields - /// - /// The handler event types to silently handle - /// - private readonly Dictionary HandlerEventTypesToSilentlyHandle; + /// + /// The handler event types to silently handle + /// + private readonly Dictionary HandlerEventTypesToSilentlyHandle; - #endregion + #endregion - #region Constructors + #region Constructors - /// - /// Initializes a new instance of the class. - /// - /// The handler event types to silently handle. - public DomainEventTypesToSilentlyHandle(Dictionary handlerEventTypesToSilentlyHandle) - { - this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle; - } + /// + /// Initializes a new instance of the class. + /// + /// The handler event types to silently handle. + public DomainEventTypesToSilentlyHandle(Dictionary handlerEventTypesToSilentlyHandle) + { + this.HandlerEventTypesToSilentlyHandle = handlerEventTypesToSilentlyHandle; + } - #endregion + #endregion - #region Methods + #region Methods - /// - /// Handles the silently. - /// - /// Name of the handler. - /// The domain event. - /// - public Boolean HandleSilently(String handlerName, - DomainEvent domainEvent) + /// + /// Handles the silently. + /// + /// Name of the handler. + /// The domain event. + /// + public Boolean HandleSilently(String handlerName, + DomainEvent domainEvent) + { + if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes) + && eventTypes.Contains(domainEvent.GetType().FullName)) { - if (this.HandlerEventTypesToSilentlyHandle.TryGetValue(handlerName, out var eventTypes) - && eventTypes.Contains(domainEvent.GetType().FullName)) - { - return true; - } + return true; + } - return false; + return false; } #endregion diff --git a/CallbackHandler.BusinessLogic/Common/IDomainEventTypesToSilentlyHandle.cs b/CallbackHandler.BusinessLogic/Common/IDomainEventTypesToSilentlyHandle.cs index 3b14789..6886e99 100644 --- a/CallbackHandler.BusinessLogic/Common/IDomainEventTypesToSilentlyHandle.cs +++ b/CallbackHandler.BusinessLogic/Common/IDomainEventTypesToSilentlyHandle.cs @@ -1,21 +1,20 @@ -namespace CallbackHandler.BusinessLogic.Common -{ - using System; - using Shared.DomainDrivenDesign.EventSourcing; +namespace CallbackHandler.BusinessLogic.Common; + +using System; +using Shared.DomainDrivenDesign.EventSourcing; - public interface IDomainEventTypesToSilentlyHandle - { - #region Methods +public interface IDomainEventTypesToSilentlyHandle +{ + #region Methods - /// - /// Handles the silently. - /// - /// Name of the handler. - /// The domain event. - /// - Boolean HandleSilently(String handlerName, - DomainEvent domainEvent); + /// + /// Handles the silently. + /// + /// Name of the handler. + /// The domain event. + /// + Boolean HandleSilently(String handlerName, + DomainEvent domainEvent); - #endregion - } + #endregion } \ No newline at end of file diff --git a/CallbackHandler.BusinessLogic/RequestHandler/CallbackHandlerRequestHandler.cs b/CallbackHandler.BusinessLogic/RequestHandler/CallbackHandlerRequestHandler.cs index ef71587..cdbaf79 100644 --- a/CallbackHandler.BusinessLogic/RequestHandler/CallbackHandlerRequestHandler.cs +++ b/CallbackHandler.BusinessLogic/RequestHandler/CallbackHandlerRequestHandler.cs @@ -1,50 +1,49 @@ using Shared.Results; using SimpleResults; -namespace CallbackHandler.BusinessLogic.RequestHandler +namespace CallbackHandler.BusinessLogic.RequestHandler; + +using System.Threading; +using System.Threading.Tasks; +using CallbackHandler.BusinessLogic.Services; +using CallbackMessageAggregate; +using MediatR; +using Requests; +using Shared.DomainDrivenDesign.EventSourcing; +using Shared.EventStore.Aggregate; + +public class CallbackHandlerRequestHandler : IRequestHandler, + IRequestHandler> { - using System.Threading; - using System.Threading.Tasks; - using CallbackHandler.BusinessLogic.Services; - using CallbackMessageAggregate; - using MediatR; - using Requests; - using Shared.DomainDrivenDesign.EventSourcing; - using Shared.EventStore.Aggregate; - - public class CallbackHandlerRequestHandler : IRequestHandler, - IRequestHandler> + private readonly ICallbackDomainService CallbackDomainService; + private readonly IAggregateRepository CallbackAggregateRepository; + + public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService, + IAggregateRepository callbackAggregateRepository) + { + this.CallbackDomainService = callbackDomainService; + CallbackAggregateRepository = callbackAggregateRepository; + } + + public async Task Handle(CallbackCommands.RecordCallbackRequest request, + CancellationToken cancellationToken) { + + return await this.CallbackDomainService.RecordCallback(request.CallbackId, + request.TypeString, + request.MessageFormat, + request.CallbackMessage, + request.Reference, + request.Destinations, + cancellationToken); + } + + public async Task> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken) { - private readonly ICallbackDomainService CallbackDomainService; - private readonly IAggregateRepository CallbackAggregateRepository; - - public CallbackHandlerRequestHandler(ICallbackDomainService callbackDomainService, - IAggregateRepository callbackAggregateRepository) - { - this.CallbackDomainService = callbackDomainService; - CallbackAggregateRepository = callbackAggregateRepository; - } - - public async Task Handle(CallbackCommands.RecordCallbackRequest request, - CancellationToken cancellationToken) { - - return await this.CallbackDomainService.RecordCallback(request.CallbackId, - request.TypeString, - request.MessageFormat, - request.CallbackMessage, - request.Reference, - request.Destinations, - cancellationToken); - } - - public async Task> Handle(CallbackQueries.GetCallbackQuery request, CancellationToken cancellationToken) - { - Result callbackAggregate = - await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken); - if (callbackAggregate.IsFailed) - return ResultHelpers.CreateFailure(callbackAggregate); - - return Result.Success(callbackAggregate.Data.GetCallbackMessage()); - } + Result callbackAggregate = + await this.CallbackAggregateRepository.GetLatestVersion(request.CallbackId, cancellationToken); + if (callbackAggregate.IsFailed) + return ResultHelpers.CreateFailure(callbackAggregate); + + return Result.Success(callbackAggregate.Data.GetCallbackMessage()); } } \ No newline at end of file diff --git a/CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs b/CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs index bf61feb..c6797f4 100644 --- a/CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs +++ b/CallbackHandler.BusinessLogic/Services/ICallbackDomainService.cs @@ -9,16 +9,15 @@ using System.Threading.Tasks; using SimpleResults; -namespace CallbackHandler.BusinessLogic.Services +namespace CallbackHandler.BusinessLogic.Services; + +public interface ICallbackDomainService { - public interface ICallbackDomainService - { - Task RecordCallback(Guid callbackId, - String typeString, - MessageFormat messageFormat, - String callbackMessage, - String reference, - String[] destinations, - CancellationToken cancellationToken); - } + Task RecordCallback(Guid callbackId, + String typeString, + MessageFormat messageFormat, + String callbackMessage, + String reference, + String[] destinations, + CancellationToken cancellationToken); } diff --git a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs index 668ac50..a5599f8 100644 --- a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs +++ b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs @@ -1,56 +1,56 @@ using Microsoft.Extensions.Logging; -namespace CallbackHandler.Bootstrapper -{ - using System; - using System.Collections.Generic; - using System.Diagnostics.CodeAnalysis; - using System.IO; - using System.Reflection; - using Common; - using EventStore.Client; - using Lamar; - using Microsoft.Extensions.Configuration; - using Microsoft.Extensions.DependencyInjection; - using Microsoft.Extensions.Diagnostics.HealthChecks; - using Microsoft.OpenApi.Models; - using Newtonsoft.Json; - using Newtonsoft.Json.Serialization; - using Shared.EventStore.Extensions; - using Shared.General; - using Shared.Middleware; - using Swashbuckle.AspNetCore.Filters; +namespace CallbackHandler.Bootstrapper; + +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Reflection; +using Common; +using EventStore.Client; +using Lamar; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; +using Microsoft.OpenApi.Models; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using Shared.EventStore.Extensions; +using Shared.General; +using Shared.Middleware; +using Swashbuckle.AspNetCore.Filters; - [ExcludeFromCodeCoverage] - public class MiddlewareRegistry :ServiceRegistry +[ExcludeFromCodeCoverage] +public class MiddlewareRegistry :ServiceRegistry +{ + public MiddlewareRegistry() { - public MiddlewareRegistry() - { - String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); - EventStoreClientSettings eventStoreSettings = EventStoreClientSettings.Create(connectionString); + String connectionString = Startup.Configuration.GetValue("EventStoreSettings:ConnectionString"); + EventStoreClientSettings eventStoreSettings = EventStoreClientSettings.Create(connectionString); - this.AddHealthChecks().AddEventStore(eventStoreSettings, - userCredentials: eventStoreSettings.DefaultCredentials, - name: "Eventstore", - failureStatus: HealthStatus.Unhealthy, - tags: new[] { "db", "eventstore" }); + this.AddHealthChecks().AddEventStore(eventStoreSettings, + userCredentials: eventStoreSettings.DefaultCredentials, + name: "Eventstore", + failureStatus: HealthStatus.Unhealthy, + tags: new[] { "db", "eventstore" }); - this.AddSwaggerGen(c => - { - c.SwaggerDoc("v1", new OpenApiInfo - { - Title = "Callback Handler API", - Version = "1.0", - Description = "A REST Api to handle callback requests from external parties API's.", - Contact = new OpenApiContact - { - Name = "Stuart Ferguson", - Email = "golfhandicapping@btinternet.com" - } - }); - // add a custom operation filter which sets default values - c.OperationFilter(); - c.ExampleFilters(); + this.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo + { + Title = "Callback Handler API", + Version = "1.0", + Description = "A REST Api to handle callback requests from external parties API's.", + Contact = new OpenApiContact + { + Name = "Stuart Ferguson", + Email = "golfhandicapping@btinternet.com" + } + }); + // add a custom operation filter which sets default values + c.OperationFilter(); + c.ExampleFilters(); //Locate the XML files being generated by ASP.NET... DirectoryInfo directory = new(AppContext.BaseDirectory); From ee9ebeeed443dd64ea2bfe1aa7561e2d848c99de Mon Sep 17 00:00:00 2001 From: "deepsource-autofix[bot]" <62050782+deepsource-autofix[bot]@users.noreply.github.com> Date: Thu, 18 Sep 2025 20:27:41 +0000 Subject: [PATCH 2/3] refactor: remove redundant new keyword for arrays This PR removes the redundant use of the `new` keyword when initializing arrays in place, streamlining array declarations for improved readability. - Redundant `new` keyword for arrays initialized in place: DeepSource flagged that using the `new` keyword when directly initializing an array literal is unnecessary. The redundant `new` syntax has been removed from `public static String[] Destinations = new[] {"A", "B"}` to simplify it to `public static String[] Destinations = {"A", "B"}`. > This Autofix was generated by AI. Please review the change before merging. --- CallbackHander.Testing/TestData.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CallbackHander.Testing/TestData.cs b/CallbackHander.Testing/TestData.cs index 9e36a31..7feaa2f 100644 --- a/CallbackHander.Testing/TestData.cs +++ b/CallbackHander.Testing/TestData.cs @@ -17,7 +17,7 @@ public class TestData public static String CallbackMessage = "Callback message"; - public static String[] Destinations = new[] {"A", "B"}; + public static String[] Destinations = {"A", "B"}; public static String Reference = "640E863C23E244BDB9717C92733FFD4C-9D20A3961CF645EDAA7BDD436318BA29"; public static Guid EstateReference = Guid.Parse("640E863C-23E2-44BD-B971-7C92733FFD4C"); From 3be3395d24dc7cd061ede54c3970c5ccf16a7263 Mon Sep 17 00:00:00 2001 From: Stuart Ferguson Date: Thu, 18 Sep 2025 21:32:53 +0100 Subject: [PATCH 3/3] :| --- .../Common/DomainEventTypesToSilentlyHandle.cs | 1 - CallbackHandler/Bootstrapper/MiddlewareRegistry.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs b/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs index 8a8514e..44fddf3 100644 --- a/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs +++ b/CallbackHandler.BusinessLogic/Common/DomainEventTypesToSilentlyHandle.cs @@ -52,5 +52,4 @@ public Boolean HandleSilently(String handlerName, } #endregion - } } \ No newline at end of file diff --git a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs index a5599f8..636663d 100644 --- a/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs +++ b/CallbackHandler/Bootstrapper/MiddlewareRegistry.cs @@ -86,5 +86,4 @@ public MiddlewareRegistry() this.AddSingleton(config); } - } }