Skip to content

Refactor MiddlewareRegistry constructor to resolve complexity violation#460

Merged
StuartFerguson merged 2 commits intomainfrom
copilot/refactor-middlewareregistry-method
Feb 27, 2026
Merged

Refactor MiddlewareRegistry constructor to resolve complexity violation#460
StuartFerguson merged 2 commits intomainfrom
copilot/refactor-middlewareregistry-method

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 27, 2026

MiddlewareRegistry::MiddlewareRegistry exceeded Codacy's 50-line complexity limit at 82 lines. Extracted the monolithic constructor into focused private methods:

  • ConfigureHealthChecks() — conditional SQL Server health check registration
  • ConfigureSwagger() — Swagger/OpenAPI doc and example filter setup
  • ConfigureAuthentication() — JWT ****** (no-op in test mode)
  • ConfigureControllers() — MVC + Newtonsoft JSON serialization settings
  • ConfigureMiddlewareLogging() — request/response logging config

Constructor is now 12 lines. No behavioral changes.

public MiddlewareRegistry()
{
    this.ConfigureHealthChecks();
    this.ConfigureSwagger();
    this.ConfigureAuthentication();
    this.ConfigureControllers();
    this.ConfigureMiddlewareLogging();
    this.ConfigureHttpJsonOptions(options =>
    {
        options.SerializerOptions.PropertyNamingPolicy = new SnakeCaseNamingPolicy();
        options.SerializerOptions.PropertyNameCaseInsensitive = true; // optional, but safer
    });
}

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 build EstateReportingAPI/EstateReportingAPI.csproj (dns block)
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/csharp/tools/linux64/Semmle.Autobuild.CSharp (dns block)
    • Triggering command: /usr/bin/dotnet dotnet restore --no-dependencies /home/REDACTED/work/EstateReportingAPI/EstateReportingAPI/EstateReportingAPI.sln --packages /tmp/codeql-scratch-f294ada2fef3658c/dbs/csharp/working/packages /p:DisableImplicitNuGetFallbackFolder=true --verbosity normal /p:TargetFrameworkRootPath=/tmp/codeql-scratch-f294ada2fef3658c/dbs/csharp/working/emptyFakeDotnetRoot /p:NetCoreTargetingPackRoot=/tmp/codeql-scratch-f294ada2fef3658c/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 MiddlewareRegistry::MiddlewareRegistry has 82 lines of code (limit is 50)</issue_title>
<issue_description>

Codacy ID: 2e19ee10e417f3bf488fdfe11c2530bc

File: EstateReportingAPI/Bootstrapper/MiddlewareRegistry.cs
Line: 20
Rule: Complexity (Warning)
Commit: 84b90cea03aba95e7c94f9cb82aeab6dd73cbec2

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

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

</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Refactor MiddlewareRegistry method to reduce complexity Refactor MiddlewareRegistry constructor to resolve complexity violation Feb 27, 2026
@StuartFerguson StuartFerguson marked this pull request as ready for review February 27, 2026 17:12
@StuartFerguson StuartFerguson merged commit 92af24c into main Feb 27, 2026
8 checks passed
@github-actions github-actions Bot deleted the copilot/refactor-middlewareregistry-method branch April 29, 2026 03:36
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 82 lines of code (limit is 50)

2 participants