Skip to content

Refactor MiddlewareRegistry constructor to reduce bootstrapper complexity#1663

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-middlewareregistry-complexity
Mar 17, 2026
Merged

Refactor MiddlewareRegistry constructor to reduce bootstrapper complexity#1663
StuartFerguson merged 2 commits intomasterfrom
copilot/fix-middlewareregistry-complexity

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

MiddlewareRegistry concentrated all middleware/service wiring into a single long constructor, exceeding the configured complexity threshold. This change keeps the registrations intact while splitting the constructor into smaller, purpose-specific configuration methods.

  • Constructor decomposition

    • Replaced the large inline registration block in MiddlewareRegistry() with focused private methods for:
      • health checks
      • Swagger
      • authentication
      • controllers / Newtonsoft JSON
      • MVC application part registration
      • client-credentials authorization wiring
      • HTTP JSON options
  • Behavior-preserving refactor

    • Kept existing registration order and configuration values unchanged.
    • Left Swagger, JWT bearer, controller serialization, and health check setup logic in place; only moved them behind named helpers.
  • Result

    • Brings the constructor under the line-count limit without changing bootstrapper responsibilities or public behavior.
public MiddlewareRegistry()
{
    String connectionString = Startup.Configuration.GetValue<String>("EventStoreSettings:ConnectionString");
    KurrentDBClientSettings eventStoreClientSettings = KurrentDBClientSettings.Create(connectionString);

    this.ConfigureHealthChecks(eventStoreClientSettings);
    this.ConfigureSwagger();
    this.ConfigureAuthentication();
    this.ConfigureControllers();
    this.ConfigureMvc();
    this.ConfigureAuthorization();
    this.ConfigureJsonOptions();
}

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 MiddlewareRegistry -p:RestoreIgnoreFailedSources=true -nologo (dns block)
    • 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)

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 MiddlewareRegistry::MiddlewareRegistry has 78 lines of code (limit is 50)</issue_title>
<issue_description>Codacy ID: e4aaf3f654183ca4d9e9593b96eb50c9

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

Message: Method MiddlewareRegistry::MiddlewareRegistry has 80 lines of code (limit is 50)

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

</issue_description>

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


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Co-authored-by: StuartFerguson <16325469+StuartFerguson@users.noreply.github.com>
Copilot AI changed the title [WIP] [Complexity] Reduce MiddlewareRegistry method line count Refactor MiddlewareRegistry constructor to reduce bootstrapper complexity Mar 17, 2026
Copilot AI requested a review from StuartFerguson March 17, 2026 12:12
@StuartFerguson StuartFerguson marked this pull request as ready for review March 17, 2026 12:54
@StuartFerguson StuartFerguson merged commit d6a13ce into master Mar 17, 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 MiddlewareRegistry::MiddlewareRegistry has 78 lines of code (limit is 50)

2 participants