Skip to content

Reduce DomainEventHandlerRegistry constructor complexity#1680

Merged
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-domain-event-handler-complexity
Mar 18, 2026
Merged

Reduce DomainEventHandlerRegistry constructor complexity#1680
StuartFerguson merged 3 commits intomasterfrom
copilot/fix-domain-event-handler-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

Codacy flagged DomainEventHandlerRegistry::DomainEventHandlerRegistry for exceeding the line-count complexity threshold. This change keeps the registration behavior intact while moving the constructor’s orchestration logic out of the constructor body.

  • Constructor simplification

    • Reduced the constructor to a single delegation call.
    • Moved service registration setup into a private helper to keep initialization readable and within the complexity limit.
  • Registration flow preserved

    • Left event handler configuration loading unchanged.
    • Kept event handler, projection, resolver, and domain event factory registrations in the same order and scope.
  • Refactor shape

    public DomainEventHandlerRegistry()
    {
        this.RegisterServices();
    }
    
    private void RegisterServices()
    {
        Dictionary<String, String[]> eventHandlersConfiguration =
            this.GetEventHandlerConfiguration($"AppSettings:{MainRegistrationName}", MainRegistrationName);
        Dictionary<String, String[]> eventHandlersConfigurationDomain =
            this.GetEventHandlerConfiguration($"AppSettings:{DomainRegistrationName}", DomainRegistrationName);
        Dictionary<String, String[]> eventHandlersConfigurationOrdered =
            this.GetEventHandlerConfiguration($"AppSettings:{OrderedRegistrationName}", OrderedRegistrationName);
    
        this.RegisterEventHandlers();
        this.RegisterProjections();
        this.RegisterResolvers(eventHandlersConfiguration, eventHandlersConfigurationDomain, eventHandlersConfigurationOrdered);
        this.AddSingleton<IDomainEventFactory<IDomainEvent>, DomainEventFactory>();
    }

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • f.feedz.io
    • Triggering command: /usr/bin/dotnet dotnet test /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.Tests/TransactionProcessor.Tests.csproj --filter VerifyBootstrapperIsValid --no-restore -nologo (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.3/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/TransactionProcessor/TransactionProcessor/TransactionProcessor.sln --packages /tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-7ae8d40573b4aa77/dbs/csharp/working/emptyFakeDotnetRoot /p:AllowMissingPrunePackageData=true (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>[Complexity] Method DomainEventHandlerRegistry::DomainEventHandlerRegistry has 58 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: a6099cf7ba0c893b98fc656657da66d1

File: TransactionProcessor/Bootstrapper/DomainEventHandlerRegistry.cs
Line: 32
Rule: Complexity (Warning)
Commit: 5b8f3e64d731c7b181b225e9d4117fda74faa3ac

Message: Method DomainEventHandlerRegistry::DomainEventHandlerRegistry has 58 lines of code (limit is 50)

**Code Snippet:**
```csharp
        public DomainEventHandlerRegistry() 
```

</issue_description>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Fix method length issue in DomainEventHandlerRegistry Reduce DomainEventHandlerRegistry constructor complexity Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 09:59
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 12:19
@StuartFerguson StuartFerguson merged commit 4df342b into master Mar 18, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Complexity] Method DomainEventHandlerRegistry::DomainEventHandlerRegistry has 58 lines of code (limit is 50)

2 participants