refactor-dotnet_skill

This skill refactors ASP.NET Core code into clean, maintainable .NET patterns, applying SRP, DI, and modern C# to reduce fat controllers and duplication.

6

GitHub Stars

1

Bundled Files

2 months ago

Catalog Refreshed

4 months ago

First Indexed

Readme & install

Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.

Installation

Preview and clipboard use veilstrat where the catalogue uses aiagentskills.

npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill refactor-dotnet

  • SKILL.md21.7 KB

Overview

This skill refactors ASP.NET Core and C# code to improve maintainability, readability, and alignment with modern .NET practices. It transforms fat controllers, duplicated logic, and legacy patterns into clean, testable code using C# 12 features, SOLID principles, and Clean Architecture. The result is smaller, focused classes, better dependency injection, and idiomatic async/await usage.

How this skill works

The skill inspects controllers, services, and data access layers to locate anti-patterns such as service locators, captive dependencies, and duplicated logic. It rewrites code to apply primary constructors, collection expressions, records, nullable annotations, and pattern matching while introducing well-scoped services, Result types, and proper EF Core usage (No-Tracking, projection, eager loading). It also suggests or implements dependency lifetimes, options pattern, and middleware improvements to align with .NET 8 practices.

When to use it

  • You have fat controllers containing business logic that should be moved to services.
  • There is duplicated code across controllers, services, or repository layers.
  • You’re upgrading to C# 12/.NET 8 and want to adopt modern language features safely.
  • A singleton depends on scoped services or you observe captive dependency/service locator anti-patterns.
  • Database queries cause N+1 issues or return too much data (no projection).

Best practices

  • Prefer constructor injection and explicit lifetimes; avoid IServiceProvider in business code.
  • Keep controllers skinny: validate input, call services, return HTTP results.
  • Extract repeated logic to services, extension methods, or small helpers to satisfy DRY.
  • Adopt primary constructors, records for DTOs, and required/init-only properties for immutable models.
  • Use No-Tracking for read queries, Include/AsSplitQuery to prevent N+1, and projection to DTOs for performance.

Example use cases

  • Refactor an OrdersController that mixes validation, mapping, and persistence into a thin controller plus OrderService using primary constructors.
  • Replace duplicated input validation across endpoints with a shared request validator and Result<T> return pattern.
  • Migrate legacy repository code to EF Core projections with AsNoTracking and fixed eager loading to eliminate N+1 queries.
  • Convert background singleton that needs DbContext to use IServiceScopeFactory to avoid captive dependency.
  • Upgrade DTOs to record types, introduce global usings, and apply collection expressions to simplify collection construction.

FAQ

The goal is behavior-preserving refactoring. Changes focus on structure, readability, and performance while keeping existing business rules intact; tests should be run to confirm.

Do you convert controllers to Minimal APIs automatically?

I recommend Minimal APIs for simple endpoints and controllers for complex scenarios. Conversion is optional and performed only when it improves clarity and maintainability.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational