Skip to content

Refactor MiddlewareRegistry constructor to clear Codacy NLOC warning#1057

Merged
StuartFerguson merged 2 commits intomasterfrom
copilot/codacy-issue-2a28420af93d82884d34c86802688567-fix
Mar 17, 2026
Merged

Refactor MiddlewareRegistry constructor to clear Codacy NLOC warning#1057
StuartFerguson merged 2 commits intomasterfrom
copilot/codacy-issue-2a28420af93d82884d34c86802688567-fix

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 17, 2026

Codacy flagged MiddlewareRegistry::MiddlewareRegistry for exceeding the configured NLOC threshold. This PR reduces constructor size without changing middleware registration behavior.

  • Constructor decomposition

    • Extracted health check registration into ConfigureHealthChecks()
    • Extracted Swagger registration into ConfigureSwagger()
    • Kept the constructor focused on orchestration only
  • Behavior preserved

    • Integration test and in-memory database branching remains unchanged
    • SQL Server health checks are registered with the same names, queries, statuses, and tags
    • Swagger document metadata, example filters, and XML comment discovery remain unchanged
    • JSON serialization options remain configured exactly as before
  • Resulting shape

    • MiddlewareRegistry() now delegates the heavy registration blocks instead of inlining them
public MiddlewareRegistry()
{
    this.ConfigureHealthChecks();
    this.ConfigureSwagger();
    this.AddSwaggerExamplesFromAssemblyOf<SwaggerJsonConverter>();

    this.ConfigureHttpJsonOptions(options =>
    {
        options.SerializerOptions.PropertyNamingPolicy = new SnakeCaseNamingPolicy();
        options.SerializerOptions.PropertyNameCaseInsensitive = true;
    });
}

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 SecurityService.sln --nologo (dns block)
    • Triggering command: /usr/bin/dotnet dotnet test SecurityService.UnitTests/SecurityService.UnitTests.csproj --nologo -v minimal (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>[Codacy] Warning issue(s) in SecurityService/Bootstrapper/MiddlewareRegistry.cs</issue_title>
<issue_description>Codacy detected 1 occurrence(s) of rule Lizard_nloc-medium:

  • Warning at SecurityService/Bootstrapper/MiddlewareRegistry.cs:26 → Method MiddlewareRegistry::MiddlewareRegistry has 57 lines of code (limit is 50)

See full details in Codacy Report

Unique ID: codacy-issue-2a28420af93d82884d34c86802688567</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>
@StuartFerguson StuartFerguson marked this pull request as ready for review March 17, 2026 09:08
Copilot AI changed the title [WIP] [Codacy] Fix long method in MiddlewareRegistry Refactor MiddlewareRegistry constructor to clear Codacy NLOC warning Mar 17, 2026
Copilot AI requested a review from StuartFerguson March 17, 2026 09:12
@StuartFerguson StuartFerguson merged commit 36708e7 into master Mar 17, 2026
9 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.

[Codacy] Warning issue(s) in SecurityService/Bootstrapper/MiddlewareRegistry.cs

2 participants