Skip to content

Reduce DomainEventHandlerRegistry constructor complexity#1673

Merged
StuartFerguson merged 4 commits intomasterfrom
copilot/a6099cf7ba0c893b98fc6565-reduce-method-complexity
Mar 18, 2026
Merged

Reduce DomainEventHandlerRegistry constructor complexity#1673
StuartFerguson merged 4 commits intomasterfrom
copilot/a6099cf7ba0c893b98fc6565-reduce-method-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 18, 2026

DomainEventHandlerRegistry had accumulated enough inline registration and configuration binding logic to exceed the complexity threshold. This change keeps the registration behavior intact while moving the constructor back to a small orchestration role.

  • Constructor split into focused helpers

    • Extracted configuration binding into GetEventHandlerConfiguration(...)
    • Extracted service registrations into:
      • RegisterEventHandlers()
      • RegisterProjections()
      • RegisterResolvers(...)
  • Registration behavior preserved

    • Existing named configuration registrations remain unchanged:
      • EventHandlerConfiguration
      • EventHandlerConfigurationDomain
      • EventHandlerConfigurationOrdered
    • Existing Lamar registrations for handlers, projections, dispatchers, resolvers, and IDomainEventFactory<IDomainEvent> are still wired the same way
  • Minor cleanup

    • Centralized registration names as private constants to remove duplicated string literals
    • Improved helper-local naming for readability

Example of the resulting constructor shape:

public DomainEventHandlerRegistry()
{
    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)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI and others added 3 commits March 18, 2026 07:17
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce lines of code in DomainEventHandlerRegistry Reduce DomainEventHandlerRegistry constructor complexity Mar 18, 2026
Copilot AI requested a review from StuartFerguson March 18, 2026 07:23
@StuartFerguson StuartFerguson marked this pull request as ready for review March 18, 2026 07:29
@StuartFerguson StuartFerguson merged commit 6707b8a 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